【www.6766.com】JS+jQuery实现注册信息的验证功能_javascript技巧_脚本之家

用JS和JQuery实现的效果是一样的。

 请填写注册信息 

 body { text-align: center; padding: 0; margin: 0; } fieldset { width: 800px; } table tr td ~ td { text-align: left; width: 600px; }

//验证用户名function check_userName() { var userName = document.getElementById.value; var regName = /[a-zA-Z]w{4,16}/ if (userName == "" || userName.trim { document.getElementById.innerHTML = "请输入用户名"; return false; } else if (!regName.test { document.getElementById.innerHTML = "由英文字母和数字组成的4-16位字符,以字母开头"; return false; } else { document.getElementById.innerHTML = "ok!!!"; return true; }}//验证昵称function check_nickName() { var nickName = document.getElementById.value; var regName = /[u4e00-u9fa5]{2,6}/ if (nickName == "" || nickName.trim { document.getElementById.innerHTML = "请输入昵称"; return false; } else if (!regName.test { document.getElementById.innerHTML = "由2-6个汉字组成"; return false; } else { document.getElementById.innerHTML = "ok!!!"; return true; }}//验证邮箱function check_email() { var email = document.getElementById.value; var regEmail = /^w+@w+$/; if (email == "" || email.trim { document.getElementById.innerHTML = "请输入邮箱"; return false; } else if ) { document.getElementById.innerHTML = "邮箱账号@域名。如good@tom.com、whj@sina.com.cn"; return false; } else { document.getElementById.innerHTML = "ok!!!"; return true; }}//验证密码function check_pwd() { var pwd = document.getElementById.value; var regPwd = /^w{4,10}$/; if (pwd == "" || pwd.trim { document.getElementById.innerHTML = "请输入密码"; return false; } else if  { document.getElementById.innerHTML = "格式错误"; return false; } else { document.getElementById.innerHTML = "ok!!!"; return true; }}//确认密码function check_pwd2() { var pwd = document.getElementById.value; var pwd2 = document.getElementById.value; if (pwd2 == "" || pwd2.trim { document.getElementById.innerHTML = "请输入密码"; return false; } else if  { document.getElementById.innerHTML = "两次输入密码不一致"; return false; } else { document.getElementById.innerHTML = "ok!!!"; return true; }}//验证手机号function check_phone() { var phone = document.getElementById.value; var regPhone = /[13,15,18]d{9}/; if (phone == "" || phone.trim { document.getElementById.innerHTML = "请输入手机号"; return false; } else if ) { document.getElementById.innerHTML = "手机号由11位数字组成,且以13,15,18开头"; return false; } else { document.getElementById.innerHTML = "ok!!!"; return true; }}//验证时间function check_date() { var birthday = document.getElementById.value; var regDate = /[13,15,18]d{9}/; if (birthday == "" || birthday.trim { document.getElementById.innerHTML = "请输入日期"; return false; } else if (!regDate.test { document.getElementById.innerHTML = "出生日期在1990-2009之间"; return false; } else { document.getElementById.innerHTML = "ok!!!"; return true; }}

 $ { var errMsg; $.each, function .blur { if  == "userName") { $; var userName = val.value; var regName = /[a-zA-Z]w{4,16}/ if (userName == "" || userName.trim { errMsg = "用户名不能为空"; } else if (!regName.test { errMsg = "由英文字母和数字组成的4-16位字符,以字母开头"; } else { errMsg = "OK!"; } $.append; } else if  == "nickName") { $; var nickName = val.value; var regName = /[u4e00-u9fa5]{2,6}/ if (nickName == "" || nickName.trim { errMsg = "昵称不能为空"; } else if (!regName.test { errMsg = "由2-6个汉字组成"; } else { errMsg = "OK!"; } $.append; } else if  == "email") { $; var email = val.value; var regEmail = /^w+@w+$/; if (email == "" || email.trim { errMsg = "邮箱不能为空"; } else if ) { errMsg = "邮箱账号@域名。如good@tom.com、whj@sina.com.cn"; } else { errMsg = "OK!"; } $.append; } else if  == "pwd") { $; var pwd = val.value; var regPwd = /^w{4,10}$/; if (pwd == "" || pwd.trim { errMsg = "密码不能为空"; } else if  { errMsg = "格式错误"; } else { errMsg = "OK!"; } $.append; } else if  == "pwd2") { $; var pwd2 = val.value; var pwd = $[3].value; if (pwd2 == "" || pwd2.trim() == "" || !pwd2.equals { errMsg = "两次输入密码不一致"; } else { errMsg = "OK!"; } $.append; } else if  == "phone") { $; var phone = val.value; var regPhone = /[13,15,18]d{9}/; if (phone == "" || phone.trim { errMsg = " 手机号不能为空 < /span>" } else if ) { errMsg = " 格式错误 < /span>" } else { errMsg = " OK! < /span>" } $.append; } else if  == "date") { $; var birthday = val.value; var regDate = /[-/][-/]/; if (birthday == "" || birthday.trim { errMsg = "请输入生日"; } else if (!regDate.test { errMsg = "格式错误"; } else { errMsg = "OK!"; } $.append;

总结

以上所述是小编给大家介绍的JS+jQuery实现注册信息的验证功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图