Regular expression to match letters, numbers, and certain symbols
I need to validate a username in PHP. It can be:
- Letters (upper and lower case)
- Numbers
- Any of these symbols :.,?!@
- Up to 15 characters OR 16 if the last character is one of the following #$^ (it can also 开发者_如何学Gobe 15 or less with one of these 3 characters at the end only)
How do I do this?
Start with this:
/^[a-zA-Z0-9:.,?!@]{3,15}[#$^]?$/
then refine it to your needs. Try to see if you need escaping of the special char, but you should get the idea.
This means: from a to z, from A to Z, from 0 to 9 and :.,?!@ repeated from 3 to 15 times, optionally followed by one among #$^
精彩评论