Documentation

Plugins/Validation/valid

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Plugins/Validation

valid( )

Checks whether the selected form is valid or whether all selected elements are valid.
validate() needs to be called on the form before checking it using this method.


Examples:

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://jzaefferer.github.com/jquery-validation/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>

NameType