I need help with two regular expressions (ASP.NET MVC 2 app). This is what I need:
Username:
- must contain at least one letter; digits are allowed but not required
- cannot contain spaces
- no special characters are allowed, such as
~!@#$%^& - underscore and “.” (dot) is allowed
- cannot start with a space or underscore
Password:
- must contain at least one letter and one number
- cannot contain spaces
- are case sensitive
I tried with [a-zA-Z0-9]+[\w.][a-zA-Z]+[\w.] for username but it failed for “a123456”
Regex for username :
another regex for username , look ahead is used..
Paolo’s regex for password is okay, but you should put ^ to the begining and $ to the end of the regex to specify begining and end of the capture..
it is stated that username can contain dot character also. I have modified the regex , but I have assumed that username can not start dot character also. here is the modified regex;