html code
<section id="register"> <div><img src="images/logo.jpg" alt="logo" /><img src="images/banner.jpg" alt="banner" /></div> <h1 class="hr_1">新用户注册</h1> <form action="" method="post" name="myform"> <dl> <>dt</Username:>dt < Dd > < INPUT ID = "User" type = "text" /> < div ID = "user_prompt" > Username 4-16 characters from the English alphabet and numbers, beginning with the letters </ div > </ dd > </ DL > < DL > < dt > password: </ dt > < dd > < INPUT ID = "pwd" type = "password" /> < div ID = "pwd_prompt" >4-10 character password of letters and numbers </ div > </ dd> </dl> <dl> <dt>确认密码:</dt> <dd><input id="repwd" type="password"/><div id="repwd_prompt"></div></dd> </dl> <dl> <dt>电子邮箱:</dt> <dd><input id="email" type="text"/><div id="email_prompt"></div></dd> </dl> <dl> <dt>手机号码:</dt> <dd><input id="mobile" type="text" /><div id="mobile_prompt"></div></dd> </dl> <dl> <dt>生日:</dt> <dd><input id="birth" type="text"/><div id="birth_prompt"></div></dd> </dl> <dl> <dt> </dt> <dd><input name="" type="image" src="images/register.jpg" class="btn" /></dd> </dl> </form> </section>
jQuery code
<script> $(function(){ $("#user").blur(checkname) $("#pwd").blur(checkpwd) $("#mobile").blur(checkmobile) $("#birth").blur(checkbirth) }) function checkname(){ var names=/^[a-zA-Z][a-zA-Z0-9]{3,15}$/ var $users=$("#user_prompt") var $user=$("#user").val() if(names.test($user)==false){ users.html $ ( " 4-16-character user name consists of letters and numbers, begin with the letter " ) return false ; } $users.html(""); return true; } function checkpwd(){ var pwds=/^[a-zA-Z0-9]{4,10}$/ var pwd=$("#pwd").val(); var $pwds=$("#pwd_prompt") if(pwds.test(pwd)==false){ pwds.html $ ( " password of letters and numbers 4-10 characters " ) return false } $pwds.html("") return true; } function checkmobile(){ var mobile=/^1[0-9]{10}$/ var mobiles=$("#mobile").val() var $mobile=$("#mobile_prompt") if(mobile.test(mobiles)==false){ mobile.html $ ( " phone number can only be a 11-digit number beginning with 1 " ) return false } $mobile.html("") return true } function checkbirth () { var Birth = / ^ ((. 19 \ D {2}) | (200 is \ D) | (201 [0-6])) - (0 [1-9] |. 1 [0-2? ?]) - (0 [1-9] | [1-2] \ d | 3 [0-1]) $ / // date of birth is not 2016 after var of the Births = $ ( " #birth " ) .val ( ); var $ Birth = $ ( " #birth_prompt " ) IF (birth.test (of the Births) == to false ) { birth.html $ ( " birthday incorrect format " ) return false } $birth.html("") return true } </script>