Skip to content

Instantly share code, notes, and snippets.

@gilesbradshaw
Created May 22, 2015 12:29
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 gilesbradshaw/56925d916d4720421840 to your computer and use it in GitHub Desktop.
Save gilesbradshaw/56925d916d4720421840 to your computer and use it in GitHub Desktop.
simple jquery valuidate
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="Scripts/jquery-1.9.1.js"></script>
<script src="Scripts/jquery.validate.js"></script>
<script>
$().ready(function () {
jQuery.validator.addMethod("mustBeGiles", function (value, element) {
return this.optional(element) || value=="giles";
}, "should be giles!!!");
$("#testForm").validate({
rules : {
giles: { mustBeGiles: true }
}
});
});
</script>
</head>
<body>
<form id="testForm">
<label for="min2">min2</label>
<input id="min2" type="text" minlength="2" >
<label for="min3">min3</label>
<input id="min3" type="text" minlength="3" >
<label for="giles">giles</label>
<input name="giles" id="giles" type="text" >
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment