Jquery 验证注册
JavaScript Code
- <script type="text/javascript">
- $(document).ready(function() {
- $.validator.addMethod("email", function(value, element) {
- return this.optional(element) || /^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+.[a-zA-Z.]{2,5}$/i.test(value);
- }, "Please enter a valid email address.");
- $.validator.addMethod("username",function(value,element){
- return this.optional(element) || /^[a-zA-Z0-9._-]{3,16}$/i.test(value);
- },"Username are 3-15 characters");
- $.validator.addMethod("password",function(value,element){
- return this.optional(element) || /^[A-Za-z0-9!@#$%^&*()_]{6,16}$/i.test(value);
- },"Passwords are 6-16 characters");
- // Validate signup form
- $("#signup").validate({
- rules: {
- email: "required email",
- username: "required username",
- password: "required password",
- },
- });
- });
- </script>
XML/HTML Code
- <form method="post" action="jqueryregthank.html" name="signup" id="signup">
- <b>Email</b><br />
- <input type="text" name="email" id='email'/><br />
- <b>UserName</b><br />
- <input type="text" name="username" id="username" /><br />
- <b>Password</b><br />
- <input type="password" name="password" id="password" /><br /><br />
- <input type="submit" value=" Sign-UP " name='SUBMIT' id="SUBMIT"/>
- </form>
原文地址:http://www.freejs.net/article_biaodan_140.html