创建正则表达式,来检查一个字符串是否是个合法的手机号
效果实现
代码示例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>js练习26</title>
<script>
var phone = /^1[3-9][0-9]{9}$/;
var hao = "18161874138";
console.log(phone.test(hao));
</script>
</head>
<body>
</body>
</html>
邮件的正则
效果实现
代码示例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>js练习26</title>
<script>
var youjian = /\w+\.\w+@[A-A-z0-9]*(\.[A-z]{2,5}){1,2}/;
var hao = "dsgagadag@163.com";
console.log(youjian.test(hao));
</script>
</head>
<body>
</body>
</html>