1. 邮箱验证
<input type="text" placeholder="请输入邮箱" id="email">
<script>
var email = document.getElementById("email");
email.onkeyup = function(event){
if(event.keyCode == 13){
var value = this.value.trim();
var reg = /^[\w]+@[0-9a-z]+\.[a-z]+$/;
console.log(reg.test(value));
}
}
/*邮箱的正则
395775347@qq.com
395775347@163.com
cheng_benchao@sina.com
chengg@gmail.com
fdfdj@xx.net
*/
/*
[\w]+@[0-9a-z]+\.[a-z]+
*/
</script>
2. 密码验证
<input type="text" placeholder="请输入密码" id="email">
<script>
var email = document.getElementById("email");
email.onkeyup = function(event){
if(event.keyCode == 13){
var value = this.value.trim();
var reg = /^[a-zA-z]+\d{5,}$/
console.log(reg.test(value))
}
}
/* 请输入6位数密码
银行密码
var reg = /^\d{6}$/
*/
/*
cheng12345 --true
cheng123 --false
账户密码
以为字母开头,后面是数字,数字至少包含5位
var reg = /^[a-zA-z]+\d{5,}$/
*/
</script>
3. 用户名验证
<input type="text" placeholder="请输入用户名" id="email">
<script>
var email = document.getElementById("email");
email.onkeyup = function(event){
if(event.keyCode == 13){
var value = this.value.trim();
var reg = /^[a-zA-Z]{1,8}$/
console.log(reg.test(value))
}
}
/*
用户名只能是字母,大小不限,不能超过8个字符
var reg = /^[a-zA-Z]{1,8}$/
*/
/*
1.电话号码验证
2.验证码验证(4)
3.密码验证
4.邮箱验证
5.用户名验证
*/
</script>