Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter Name Validation

Tags:

regex

twitter

In our registration form we now want to ask the user to enter their twitter name (eg @paul).

Can anyone tell what characters are allowed in it?

e.g. a-z, A-Z, underscores, 0-9

anything else?

like image 928
knookie Avatar asked Jul 06 '12 11:07

knookie


2 Answers

I believe it's letters, numbers and underscores only, and a maximum of 15 characters.

A quick search unveiled this post (non-Twitter) covering the same topic:

http://kagan.mactane.org/blog/2009/09/22/what-characters-are-allowed-in-twitter-usernames/

The above post also contains regex examples to help you validate:

Full regex – /^[a-zA-Z0-9_]{1,15}$/
Perl-compatible regex – /^\w{1,15}$/
like image 106
Matt Gifford Avatar answered Nov 07 '22 01:11

Matt Gifford


This is the final JavaScript Funcion:

function validTwitteUser(sn) {
    return /^[a-zA-Z0-9_]{1,15}$/.test(sn);
}
like image 39
Rodrigo Polo Avatar answered Nov 07 '22 00:11

Rodrigo Polo