Can we use regular expressions to find out if a string follows these rules?
- Not have upper-case letters.
- Begin with a letter.
- Have at least 1 digit(s) not at the beginning and end.
- Have up to 8 alphanumeric
- Does NOT have any symbols like @#$ characters (symbols like !@#$%^&*()-+).
EDIT: I’ve updated the regular-expression in the code with one which looks to work.
@"^[a-z](?=[a-z0-9@#\$]*[0-9][a-z0-9@#\$]*)[a-z0-9@#\$]{0,6}[a-z@#\$]$"EDIT: I’ve tweaked the code. One of the tests was
aa1@aaaamarked as being expected to fail when it should succeed as pointed out by Douglas.I’ve verified that the regular-expression offered by Douglas works just as well and its shorter too.
Not an answer as such, but here’s a quick test-rig. I’ve used the regular expression and tests from @ShaunWilde’s answer.
Unfortunately, the tests don’t return the expected results :-|.