Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to validate a twitter url

Tags:

jquery

regex

I'm using the jQuery validation engine to parse my form data: https://github.com/posabsolute/jQuery-Validation-Engine

What would be the regex to validate a twitter URL (including the http://twitter.com part) Eg:

http://twitter.com/barackobama
or
http://twitter.com/#!/barackobama
like image 914
Alex Avatar asked May 17 '11 00:05

Alex


People also ask

How do I verify my twitter URL?

You can verify your Twitter card in 3 easy steps: Choose the card type. Add it to your site using correct metatags. Verify the URL through the Twitter card validator for a successful log message.

How do I find the RegEx for a URL?

Match the given URL with the regular expression. In Java, this can be done by using Pattern. matcher(). Return true if the URL matches with the given regular expression, else return false.

What is URL RegEx?

URL regular expressions can be used to verify if a string has a valid URL format as well as to extract an URL from a string.

What is RegEx in validation?

RegEx validation is essentially a syntax check which makes it possible to see whether an email address is spelled correctly, has no spaces, commas, and all the @s, dots and domain extensions are in the right place.


2 Answers

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

with optional using https or add www e.g

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

is valid

like image 125
morgan9999 Avatar answered Oct 12 '22 21:10

morgan9999


You mean

/http(?:s)?:\/\/(?:www\.)?twitter\.com\/([a-zA-Z0-9_]+)/
like image 25
SLaks Avatar answered Oct 12 '22 23:10

SLaks