How can I validate a name in Javascript using Regex? I tried with /^([a-zA-Z.]){3,50}$/ validation expression but it does not completely satisfy my needs.
Valid Names can be (Total Name Length between 3 and 50)
- John
- Antony Simon
- Kevin M D
- James.K
- James KJ
- James K.J
Invalid names can be
- 121212
- aaa12212
- 3434fgfgf
- James..
- James .
- James ..dfgdf
- ........................
- ... .....
-
Please help.
Hi,
Please consider below regex.
^[a-z][\w]{3,20}([\.\s][\w]{1,30})?
^[a-z]: begin with a-z
[\w]{3,20} append with any word character including underscore, you could config this length, (in order to match Kevin M D James K.J, please consider[a-zA-Z0-9\s] instead of [\w]
([\.\s][\w]{1,30})? match the name contains " " or "."
This is just a suggestion for you, please modify this according with your requirement.
Best Regards,
Jambor
沒有留言:
張貼留言