tags:

views:

50

answers:

1

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 be 15 or less with one of these 3 characters at the end only)

How do I do this?

+3  A: 

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 #$^

Palantir
+1 He doesn't say anything about the min-length.
Amarghosh
Got it: `/^[A-Za-z0-9:\.,\?!@]{1,15}[#\$\^]?$/` Thanks for that. Now I just need to find out if there are any other special characters I need to allow.
Hintswen