From jQuery JavaScript Library
« Back to Plugins/Validation
valid( )
Checks if the selected form is valid or if all selected elements are valid.
validate() needs to be called on the form before checking it using this method.
Examples:| Name | Type |
Sets up validation for a form, then checks if the form is when clicking a button valid.
$("#myform").validate();
$("a.check").click(function() {
alert("Valid: " + $("#myform").valid());
return false;
});
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/lib/jquery.delegate.js"></script>
<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></script>
<script>
$(document).ready(function(){
$("#myform").validate();
$("a.check").click(function() {
alert("Valid: " + $("#myform").valid());
return false;
});
});
</script>
</head>
<body>
<form id="myform">
<input type="text" name="name" class="required" />
<br/>
<a href="#" class="check">Validate!</a>
</form>
</body>
</html>