37 sites, 19,920 entries and counting...     Get a free blog; Join a Weblog Network!
Top

Regex For Creating Usernames

January 9, 2009

A regular expression (called regex) is a way for a programmer to instruct how a program should look for a specified pattern in text and then what it should do when each pattern match is found. Rather than going through each character of a string and doing matches, regex makes life easier for programmers to do search and matches. This sample regex is a good pattern for use in creating usernames.

The regex below means that only alphanumeric (only lowercase letters) are allowed including an underscore and a dot.

^[a-z0-9_.]$

Comments

One Response to “Regex For Creating Usernames”

  1. Mikuso on February 20th, 2009 9:25 am

    With Regex like that, your usernames would only be allowed to be one character long.

    Try something like this instead:
    ^[a-z0-9_.]+$

Got something to say?





Renegade Motorhomes - Credit Card Consolidation - Debt Consolidation - Credit Consolidation
Bottom