Username regular expression

A

Andy G

I am trying to validate a username text box. This text box comes off of a
registration form where the user types in a username, I want to validate
that they used between 6 and 15 alphanumeric characters in the username.
Could be all numbers or all characters or a combination of the 2 and allow
one of the each @ , underscore , and period.

Here is what I have so far:
([a-zA-Z0-9]{6,15})$

Thanks!
 
G

Guest

The requirement that they allow one of each @ _ and period makes this tricky.
The only way I can think of to do this is to use a zero-width positive
lookahead.

^((?=[^\.]*\.?[^\.]*)(?=[^_]*_?[^_]*)(?=[^@]*@?[^@]*)[a-zA-Z0-9]{6,15})$

DISCLAIMER: I haven't tested this.

Basically it's ensuring that the matched expression only has at most one @ _
or .

http://haacked.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top