Following are the code for domain name validation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
<!DOCTYPE html> <html> <body> <h1>Web Url Validation</h1> <input type='text' name='Website' id='Website'> <button id="mybutton" onclick="myFunction()">Validate</button> <p style="color:red" id="error"></p> <script> function myFunction() { var text = document.getElementById("Website").value; var pattern = /^(http[s]?:\/\/){0,1}(www\.){0,1}[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,5}[\.]{0,1}/; if (!pattern.test(text)) { document.getElementById("error").innerHTML = "Invalid domain"; } else { document.getElementById("error").innerHTML = "Valid domain"; } } </script> </body> </html> |