Tuesday, April 27, 2010
How to validate Website Address using Regular Expressions?
Regular Expression for Valid Website Address
Problem:
How to valid the input for a website address in your javascript using regular expression? - A key question many of us are struggling to find an answer.
Is there really a regular expression that will seize invalid website address?
Fortunately, the answer is yes.
Solution:
The above regular expression shall be used in your regex functions in any programming language to seize the invalid website address.
Example (using Python):
Problem:
How to valid the input for a website address in your javascript using regular expression? - A key question many of us are struggling to find an answer.
Is there really a regular expression that will seize invalid website address?
Fortunately, the answer is yes.
Solution:
Regex_Pattern = "/^((https?|ftp|news):\/\/)?www\.([a-z]([a-z0-9\-]*)+\.(aero|arpa|asia|biz|cat|com|coop|edu|gov|info|int|jobs|lan|mil|mobi|museum|nato|name|net|org|pro|store|tel|travel|web|[a-z]{2}|[a-z]{2}\.[a-z]{2}))$/"
The above regular expression shall be used in your regex functions in any programming language to seize the invalid website address.
Example (using Python):
result = re.match(Regex_Pattern, website_string)
Subscribe to:
Post Comments
(
Atom
)
2 comments :
Very Useful thanks :)
Welcome Sushant :-)
Post a Comment