ppp
ppp

Reputation: 303

regular expression for web url

I am using a regular expression for validation web url. that is not validating more than one dots(.) like www.gmail.....com, other than this it is working fine.can any body update my regular expression-

^[a-zA-Z0-9\-\.]+\.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU)$

Upvotes: 0

Views: 976

Answers (3)

codevania
codevania

Reputation: 505

Why don't you use +? [\.]+ could be matched with one more .!

Upvotes: 0

El Ronnoco
El Ronnoco

Reputation: 11912

UPDATE. Note this is not foolproof by any means.

^([a-zA-Z0-9\-]+\.)+(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU)$

The + tells the regex to match one or more times

Upvotes: 2

Marcelo Cantos
Marcelo Cantos

Reputation: 186108

For Perl-compatible regex syntax, you can do this:

^([a-zA-Z0-9-]|\.(?!\.))+\.(com|...

Also, this is very US-centric. My company's domain ends in .com.au.

Upvotes: 0

Related Questions