How to test for a valid twitter handle using a regular expression

I use Redmine CRM, which allows custom fields in the Contacts, Deals and other modules.  The validity of an entry may be tested with a regular expression.  I had to do quite a bit of testing before I finally got it right (not doing this every day!), so here is what I ended up using:

^@([A-Za-z0-9_]+{1,15}$)

Meaning is should start with an “@” and then have at least 1 of A-Z, a-z, 0-9 or _, but not more than15.

Hope this helps someone else somewhere, sometime 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s