Last active
October 13, 2015 05:48
-
-
Save ElmahdiMahmoud/4148596 to your computer and use it in GitHub Desktop.
plugin: jquery form validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| markup | |
| ------ | |
| <div class="scan-form"> | |
| <h1> <span>Start</span> your free scan now!</h1> | |
| <form id="sacnForm" action="javascript:alert('success!');"> | |
| <input type="text" name="scanBar" id="scanBar" placeholder="Your website URL" value="" /> | |
| <input type="submit" value="start"> | |
| </form> | |
| <div class="alerts"> | |
| <small></small> | |
| <p></p> | |
| </div> | |
| </div> | |
| jQuery | |
| ------ | |
| function validateURL(textval) { | |
| var urlregex = new RegExp( | |
| "^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([0-9A-Za-z]+\.)"); | |
| return urlregex.test(textval); | |
| } | |
| $("#sacnForm").submit(function() { | |
| if (validateURL($("#scanBar").val())) { | |
| $("#scanBar").removeClass("error"); | |
| return true; | |
| } | |
| if ($("#scanBar").val().length >= 40) { | |
| $(".alerts p").text("URL has to be less than 40 characters").show(); | |
| } | |
| if ($("#scanBar").val() == "") { | |
| $("#scanBar").attr("placeholder","Put your URL here to start scan!"); | |
| $("#scanBar").css('border','3px solid #ffbf32'); | |
| return false; | |
| } | |
| $("#scanBar").keyup(function(){ | |
| $(".alerts").slideUp(); | |
| $("#scanBar").removeClass("error"); | |
| }); | |
| $("#scanBar").click(function(){ | |
| $("#scanBar").select(); | |
| }); | |
| $("#scanBar").addClass("error"); | |
| $(".alerts p").text($("#scanBar").val() + 'Not valid!').show(); | |
| $(".alerts").fadeIn(); | |
| return true; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment