Created
June 8, 2011 07:21
-
-
Save maxim75/1013962 to your computer and use it in GitHub Desktop.
Using jquery.validate.js
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> | |
<style> | |
.field | |
{ | |
border: 1px solid #999; | |
} | |
label.error | |
{ | |
color: Red; | |
} | |
</style> | |
<!-- Google Maps --> | |
<!-- | |
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"> | |
</script> | |
--> | |
<link href="jquery-ui-1.8.13.custom.css" media="screen" rel="stylesheet" type="text/css" /> | |
<!-- JQuery --> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script> | |
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.js"></script> | |
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.8/jquery.validate.js"></script> | |
</head> | |
<body> | |
<div class="error" style="display:none;"> | |
<span /> | |
</div> | |
<form action="" id="commentForm"> | |
<div class="field"> | |
<label for="name">Username:</label> | |
<input type="text" name="username" /> | |
</div> | |
<div class="field"> | |
<label for="name">State:</label> | |
<input type="text" name="name" /> | |
</div> | |
<input type="submit" value="OK" /> | |
</form> | |
<script> | |
jQuery.validator.addMethod("auState", function(value, element) { | |
return (value == "NSW") || (value == "VIC"); | |
}, "Hello"); | |
$("#commentForm").validate({ | |
debug: true, | |
rules: { | |
"name": "required auState" | |
}, | |
messages: { | |
"name": | |
{ | |
required: "req", | |
auState: "AU state" | |
} | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment