Created
May 25, 2016 05:52
-
-
Save kahneraja/d354b41408bf8d6267f0dc91a6c2e9a8 to your computer and use it in GitHub Desktop.
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script> | |
<script src="http://ajax.microsoft.com/ajax/jquery.validate/1.15.0/jquery.validate.min.js"></script> | |
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.15.0/additional-methods.min.js"></script> | |
<script> | |
$(document).ready(function(){ | |
$.validator.addMethod("mustbeyoungerthan", function(value, element) { | |
var max = $(element).attr('data-rule-mustbeyoungerthan'); | |
if (parseInt(value) > parseInt(max)) | |
return false; | |
return true; | |
}, "Default error message."); | |
$("#registerForm").validate(); | |
}); | |
</script> | |
</head> | |
<body> | |
<h1>Form Validation Example</h1> | |
<form id='registerForm' name='registerForm' method='post' action='' class="validate" > | |
<p> | |
Name: <input type='text' name='name' id='name' class='required' /> | |
</p> | |
<p> | |
Email: <input type='text' name='email' id='email' class='required' /> | |
</p> | |
<p> | |
Age: <input type='text' name='age' id='age' data-rule-mustbeyoungerthan="50" data-msg-mustbeyoungerthan="Invalid age range."/> | |
</p> | |
<p> | |
<input type='submit' name='Submit' value='Submit' /> | |
</p> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment