笔记——《正则表达式》

记录下最近项目中用到的正则嘻嘻

<!DOCTYPE html>
<html>

<head>
    <title>正则</title>
</head>

<body>
    <div style="width: 200px;margin: 0 auto">
        <input type="text" name="" id="txt">
        <button id="jiaoyan" onclick="jiaoyanFun()">校验</button>
    </div>
</body>
<script type="text/javascript">
let isPhone, regEmail, quKongGe,isName,isPwd,isZimu;
isPhone = /^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/; //手机
regEmail = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/; //邮箱
isName = /^[A-Za-z0-9\u4e00-\u9fa5]{4,30}$/;//只能为中文、数字、英文字母(区分大小写), 特殊字符不允许使用;4-30位字符
isPwd = /^[A-Za-z0-9_-]{6,16}$/;//密码只能为数字、英文字母(区分大小写)、“_”,其他特殊字符不
// 可以使用;密码为6-16位字符;
isZimu = /^[a-z]*$/;
function jiaoyanFun(argument) {
    var txtValue = document.getElementById("txt").value;
    quKongGe = txtValue.replace(/(^\s*)|(\s*$)/g, "");//去除前后空格
    if(!isPhone.test(quKongGe)){
        alert('手机号格式不正确');
    }
}
</script>

</html>

 

posted @ 2018-03-28 14:00  爱喝酸奶的吃货  阅读(203)  评论(0编辑  收藏  举报