Skip to content

Instantly share code, notes, and snippets.

@kahneraja
Created May 25, 2016 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kahneraja/d354b41408bf8d6267f0dc91a6c2e9a8 to your computer and use it in GitHub Desktop.
Save kahneraja/d354b41408bf8d6267f0dc91a6c2e9a8 to your computer and use it in GitHub Desktop.
<!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