Domain name validation using jquery
Please see the below code for the domain name validation using jquery
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 32 33 34 35 36 37 |
<!DOCTYPE html> <html> <body> <h1>Web Url Validation</h1> <form method="post" action="insert.php" id="myform"> <input type='text' name='Website' placeholder="Your Domain.com" id="Website" class='form-control placeholder'/> <button type="submit" id="singlebutton" name="submitRFQ" class="btn more red-background no-border content-sub">VALIDATE</button> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.js"></script> <script> jQuery.validator.addMethod("myCustomMethod", function( value, element ) { return this.optional(element) || /^(http[s]?:\/\/){0,1}(www\.){0,1}[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,5}[\.]{0,1}/i.test(value); }, 'Please enter a valid URL.'); $("#myform").validate({ onfocusout: function(element) { this.element(element); }, rules: { Website: { required: true, myCustomMethod: true }, }, messages: { FirstName: "First name is required.", LastName: "Last name is required.", } }); </script> </body> </html> |