PNG PNG - 1 year ago 124
Javascript Question

How to validate domain name using regex?

This is my code for validating domain name.

function frmValidate()
var val=document.frmDomin;
if (/^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9]\.[a-zA-Z]{2,}$/.test({
alert("Enter Valid Domain Name");;
return false;


<form name="frmDomin" action="" method="post" onsubmit="return frmValidate();">
Domain Name : <input type="text" value="" id="name" name="name" />

Now I entered
and it alert the message. I want to enter sub domain also. How to change this? I should not get alert.

Answer Source

Try this:



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download