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(val.name.value)) {
}
else {
alert("Enter Valid Domain Name");
val.name.focus();
return false;
}
}
and
<form name="frmDomin" action="" method="post" onsubmit="return frmValidate();">
Domain Name : <input type="text" value="" id="name" name="name" />
</form>
Now I entered http://devp1.tech.in
and it alert the message. I want to enter sub domain also. How to change this? I should not get alert.
RegEx pattern validation can be added to text input type questions. To add validation, click on the Validation icon on the text input type question.
The Validation (Regex) property helps you define a set of validation options for a given field. In general, this field property is used to perform validation checks (format, length, etc.) on the value that the user enters in a field. If the user enters a value that does not pass these checks, it will throw an error.
The validation of FQDN object is performed using RegEx pattern ^([a-zA-Z0-9. _-])+$ by the system to determine if a given hostname uses valid characters. Where ^ specifies start of a string, and $ specifies end of a string and + indicates one or more strings in the Round Brackets. [a-zA-Z0-9.
Try this:
^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9](?:\.[a-zA-Z]{2,})+$
Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With