-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegExpEmail.html
38 lines (37 loc) · 1.1 KB
/
RegExpEmail.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>邮箱验证 + 电话号码验证</title>
</head>
<body>
<input id="telephone" placeholder="请输入您的电话号码"/><button id="btn">点击验证</button>
<br/>
<input id="Email" placeholder="请输入您的邮箱"/><button id="btn2">点击验证</button>
</body>
<script>
var telephone = document.getElementById("telephone");
var btn = document.getElementById("btn");
var reg =/^1\d{10}$/;
var reg2 =/^\d{4}-\d{7}$/;
btn.onclick = function(){
if(reg.test(telephone)){
alert("这个是手机号码");
}else if(reg2.test(telephone)){
alert("这个是座机号码");
}else{
alert("请重新输入");
}
};
var Email = document.getElementById("Email");
var btn2 = document.getElementById("btn2");
var reg3 =/^\w{6,18}@\w{2,4}\.\w{3}/g;
btn2.onclick = function() {
if (reg3.test(Email)) {
alert("邮箱注册成功");
} else {
alert("邮箱注册失败");
}
};
</script>
</html>