如何使用 jQuery Validation 插件验证正则表达式?在这段代码中,我们可以使用一个 jQuery 插件“jQuery Validation”插件来验证表单,但我不知道使用这个插件来验证正则表达式。
<!DOCtype html>
<html>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/additional-methods.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/additional-methods.min.js"></script>
<body>
<form method="post" name="signup_form" enctype="multipart/form-data">
<table>
<tr><td>First Name:</td><td><input type="text" name="first_name" placeholder="First name" required><span> *</span></td></tr>
<tr><td>Middle Name:</td><td><input type="text" name="middle_name" placeholder="Middle Name"></td></tr>
<tr><td>Last Name:</td><td><input type="text" name="last_name" placeholder="Last Name" required><span> *</span></td></tr>
<tr><td>Username:</td><td><input type="text" name="username" placeholder="Username" required><span> *</span></td></tr>
<tr><td>Password:</td><td><input id="password1" type = "password" name="password" required/><span> *</span></td></tr>
<tr><td>Re-Enter Password:</td><td><input class="left" id="password_again" type = "password" name="password_again" required/><span> *</span></td></tr>
<tr><td>Email:</td><td> <input id="email" type="email" name="email" required/><span> *</span></td></tr>
<tr><td>Gender:</td><td><input type="radio" name="gender" value="male" required>Male <input type="radio" name="gender" value="female" required> Female<span> *</span></td></tr>
<tr><td>Date of Birth:</td><td><select name = "day" required><option value="">Day</option>
<?php for($i = 1; $i < 32; $i++){?>
<option value = "<?php echo $i;?>"><?php echo $i;?></option>
<?php }?>
</select>
<select name="month" required><option value="">Month</option>
<option value = "jan">Jan</option>
<option value = "feb">Feb</option>
<option value = "mar">Mar</option>
<option value = "apr">Apr</option>
<option value = "may">May</option>
<option value = "jun">Jun</option>
<option value = "jul">Jul</option>
<option value = "aug">Aug</option>
<option value = "sep">Sep</option>
<option value = "oct">Oct</option>
<option value = "nov">Nov</option>
<option value = "dec">Dec</option>
</select>
<select name = "year" required><option value="">Year</option>
<?php for($i = 2013; $i > 1904; $i--){?>
<option value = "<?php echo $i;?>"><?php echo $i;?></option>
<?php }?>
</select><span> *</span></td></tr>
<tr><td>Address Line 1:</td><td><input type="text" name="address1" placeholder="Address Line 1" required><span> *</span></td></tr>
<tr><td>Address Line 2:</td><td><input type="text" name="address2" placeholder="Address Line 2"></td></tr>
<tr><td>Country:</td><td><input type="text" name="country" placeholder="Country" required><span> *</span></td></tr>
<tr><td>State:</td><td><input type="text" name="state" placeholder="State" required><span> *</span></td></tr>
<tr><td>City:</td><td><input type="text" name="city" placeholder="City" required><span> *</span></td></tr>
<tr><td>Pincode:</td><td><input type="text" name="pincode" placeholder="Pincode" required><span> *</span></td></tr>
<tr><td colspan="2" align="center">
<input type="submit" value="Enter" formaction="sucess.php"></td></tr>
</table>
<script >
$("#signup_form" ).validate();</script>
</form>
</body>
</html>