I'm working on a regex to validate a form field's input. I've just begun to learn about regular expressions and would like to see if anyone has any feedback.
What I'm trying to do:
- The input can contain multiple words
- Can not contain any symbols other than white space and - (dash)
- I don't want the first character to be a number
- After the first character the string can be alpha-numeric
- My Name
- Another-Name Folks
- 1or The Other
- *Hello Dr. *Jones
- What_is_Going on
Here's what I came up with:
It seems to be working fine, but I'm not sure if there are any shortcuts I may be able to use, or if I'm leaving anything out.
ok, after some more testing I've come up with this process:
First I strip any white space from the begin and the end of the string using this regex: ^\s+|\s+$
Then I perform a validation check using this regex: ^[A-z]+[A-z0-9\s-]+[A-z0-9]$
This topic is now closed. New replies are no longer allowed.