Reputation: 6665
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
Upvotes: 13
Views: 21574
Reputation: 887867
You mean
/http(?:s)?:\/\/(?:www\.)?twitter\.com\/([a-zA-Z0-9_]+)/
Upvotes: 14
Reputation: 759
You should consider differences between http and https and of course www. Many of answer forget this rule.
'/^(?:https?:\/\/)?(?:www\.)?twitter\.com\/(#!\/)?[a-zA-Z0-9_]+$/i'
Upvotes: 2
Reputation: 801
/(?: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
Upvotes: 15
Reputation: 395
I'm not familiar with jQuery but if it uses standard regex it would be something like this:
http://twitter.com/(#!/)?[a-zA-Z0-9_]{1,15}
This bit (#!/)?
is to make the #!/ optional, and this [a-zA-Z0-9_]{1,15}
is because Twitter usernames can contain letters (upper or lowercase), numbers and underscores and can be up to 15 characters in length.
Upvotes: 2