js(正则验证)
onKeyDown : function(event){
if(event.KeyCode == 13)//按下Enterjian
{
..........//其他操作
}
}
其余jian对应:https://www.cnblogs.com/viola-sh/articles/5007485.html
var emailBoolean=false //密码 $("#pass").blur(function () { var pass = this.value; if (/^(?![a-z]+$)(?![0-9]+$)[a-zA-Z0-9]{6,16}$/.test(pass)) { return true; } //停留2秒后消失,在停留的时候,透明度为1.0什么都不做 $(‘<sapn id="add" class="quick-alert">密码格式错误</sapn>‘).insertAfter($("#title")).animate({opacity: 1.0}, 2000).fadeOut("slow", function () { //隐藏时把元素删除 $(this).remove(); }); return false; }); //查询邮箱是否已经注册 $("#email").blur(function () { $.ajax({ url:"/check/checkEmail", type:"GET", data:{"email":this.value}, dataType:"json", success:function(data){ if(data.no==9){ console.log(data.message) emailBoolean=true }else{ console.info(data.message) console.log(data.message) console.debug(data.message) } } }); }); //验证邮箱规则 function checkEmail() { var email = document.getElementById("email").value; if (/^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test(email)) { return true; } return false; } //提交数据 $("#btn1").click(function () { console.log(checkEmail()) console.log(emailBoolean) if (!checkEmail()||!emailBoolean) { return; } var password=document.getElementById("pass").value; var email=document.getElementById("email").value; $.ajax({ url: "/check/checkLogin", type: "POST", dataType: "json", data:JSON.stringify({"password": password, "email": email}), beforeSend: function(request){ request.setRequestHeader("token", "123456789"); }, headers: { "content-Type": "application/json; charset=utf-8" }, success: function (data) { if(data.no==8){ alert(data.message.toString()) } if(data.no==9){ localStorage.setItem("USER_TOKEN_KEY",data.data.toString()) window.location.href = "/login/toGoal"; } if(data.no==10){ alert(data.message.toString()) } if(data.no==12){ console(data.message.toString()) } }, error: function (data) { alert("网络异常") } }); }); password=‘‘ email=‘‘ //去注册页面 $("#a2").click(function () { window.location.href="../../user/registe" }) //去找回密码页面 $("#a1").click(function(){ window.location.href="../../user/forgetPassword" });
//验证手机号规则 function checkPhone() { phone = document.getElementById("phone").value; if (/^1[3456789]\d{9}$/.test(phone)) { return true; } return false; }