Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<!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
You can’t perform that action at this time.