I\'m currently using this regex ^[A-Z0-9 _]*$
to accept letters, numbers, spaces and underscores. I need to modify it to require at least one number or letter s
This will validate against special characters and leading and trailing spaces:
var strString = "Your String";
strString.match(/^[A-Za-z0-9][A-Za-z0-9 ]\*[A-Za-z0-9]\*$/)
You can use a lookaround:
^(?=.*[A-Za-z0-9])[A-Za-z0-9 _]*$
It will check ahead that the string has a letter or number, if it does it will check that the rest of the chars meet your requirements. This can probably be improved upon, but it seems to work with my tests.
UPDATE:
Adding modifications suggested by Chris Lutz:
^(?=.*[^\W_])[\w ]*$/