Regex to check twitter url

I use the jQuery validation mechanism to parse my form data: https://github.com/posabsolute/jQuery-Validation-Engine

What will be the regular expression for checking twitter url (including http://twitter.com ) For example:

http://twitter.com/barackobama or http://twitter.com/#!/barackobama 
+7
source share
6 answers

Do you mean /http(?:s)?:\/\/(?:www\.)?twitter\.com\/([a-zA-Z0-9_]+)/

+7
source
 /(?:http:\/\/)?(?:www\.)?twitter\.com\/(?:(?:\w)*#!\/)?(?:pages\/)?(?:[\w\-]*\/)*([\w\-]*)/ 

with additional use of https or adding www for example

 http://twitter.com/example https://twitter.com/example http://www.twitter.com/example https://www.twitter.com/example 

really

+6
source

I am not familiar with jQuery, but if it uses a standard regex, it will be something like this:

 http://twitter.com/(#!/)?[a-zA-Z0-9_]{1,15} 

This bit (#!/)? should do #! / optional, and this [a-zA-Z0-9_]{1,15} is that Twitter usernames can contain letters (upper or lower case), numbers and underscores, and can contain up to 15 characters.

+2
source

You must consider the differences between http and https and, of course, www . Many of the answers have forgotten this rule.

 '/^(?:https?:\/\/)?(?:www\.)?twitter\.com\/(#!\/)?[a-zA-Z0-9_]+$/i' 
+1
source

What about:

 http:\/\/twitter\.com\/(#!\/)?\w+ 
0
source
 url.match(/http:\/\/twitter.com\/(#!\/)?(\w*)/i); 
0
source

All Articles