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
Valid Examples:
- My Name
- SomeName1
- Another-Name Folks
Invalid Examples:
- 1or The Other
- *Hello Dr. *Jones
- What_is_Going on
Here’s what I came up with:
[1]+[A-z0-9\s-]+[A-z0-9]
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.
A-z ↩︎