I would like to have a regex which matches the string with NO whitespace(s) at the beginning. But the string containing whitespace(s) in the middle CAN match. So far i have
If your field for user name only accept letters and middle of space but not for begining and end
User name: /^[^\s][a-zA-Z\s]+[^\s]$/
If your field for user ID only accept letters,numbers and underscore and no spaces allow
user ID: /^[\w]+$/
If your field for password only accept letters,number and special character no spaces allow
Password: /^[\w@#&]+$/
Note: \w
content a-zA-Z
, number
, underscore (_
) if you add more character, add you special character after \w
.
You can compare with user ID and password field in password field im only add some special character (@#&
).
India public thoko like
In your 2nd character class, \\s
will match \
and s
, and not \s
. Thus it doesn't matches a whitespace. You should use just \s
there. Also, move the hyphen towards the end, else it will create unintentional range in character class:
^[^-\s][a-zA-Z0-9_\s-]+$