Domain Validation

I have this regex -- /^([0-9a-zA-Z\-]+\.)+[a-zA-Z]{2,6}(\:[0-9]+)?(\/\S*)?$/ which is not that effective.

Did any guy have a good tested regex for validating domain name.

 #

Below is good tested regex for validating domain name

(([a-zA-Z0-9]|%[a-fA-F0-9]{2})(-([a-zA-Z0-9]|%[a-fA-F0-9]{2})+)?\.)+([a-zA-Z]{2,7}\.?)
 
 #

The following regex is very simple and i have used it for validating domain names

/^([a-z0-9][a-z0-9\-]*[a-z0-9]\.){2,}$/
 
 #

Thought of taking the discussion further you can try this regex

/^([a-z0-9]([-a-z0-9]*[a-z0-9])?\.)+((a[cdefgilmnoqrstuwxz]|aero|arpa)|
(b[abdefghijmnorstvwyz]|biz)|(c[acdfghiklmnorsuvxyz]|cat|com|coop)|
d[ejkmoz]|(e[ceghrstu]|edu)|f[ijkmor]|(g[abdefghilmnpqrstuwy]|gov)|
h[kmnrtu]|(i[delmnoqrst]|info|int)|(j[emop]|jobs)|k[eghimnprwyz]|
l[abcikrstuvy]|(m[acdghklmnopqrstuvwxyz]|mil|mobi|museum)|
(n[acefgilopruz]|name|net)|(om|org)|(p[aefghklmnrstwy]|pro)|
qa|r[eouw]|s[abcdeghijklmnortvyz]|(t[cdfghjklmnoprtvwz]|travel)|
u[agkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw])$/i

 

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.

Cumulus Tag Cloud

Kiran Says

SEO Architect,SEO Specialist reflect my values.

By enduring black hat methods the SEO industry is setting itself up for washout and sleepwalking into oblivion.

Jobs in India