正则表达式与H5表单

 RegExp 对象
    exec 检查字符中是正则表达中的区域
    text  检查内容
  String 对象的方法
    match
    search
    replace
    splict
正则表达式符号
    /.../ 开始与结束     ^开始    $结束
     /s 任何空白字符     /S任何非空白 
    /d  匹配数字    /D除去任何数字的字符    
    /w  变量命名规则    {n}匹配前一项N次   
     {n,}匹配前一项N次 或者多次    {n,m} 匹配至少n次 但不能超过m次
示例:var reg = /^1([3-5]|[7-8])d{9}$/

HTML5  实战
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title></title>
        <script src="js/jquery-3.1.1.js"></script>
        <script type="text/javascript">
            $(function(){
                $('#Go_submit').click(function(){
                    var obj_ =document.getElementById('form_tel');
                    if(obj_.validity.valueMissing==true){
                        obj_.setCustomValidity('手机号不能为空哦')
                    }else if(obj_.validity.patternMismatch == true){
                        obj_.setCustomValidity('请填写正确的手机号')
                    }
                    //如果判断邮箱那么可以
                    xx.validity.typeMismatch  //可以判断邮箱
                })
            });
        </script>
    </head>
    <body>
        <form action="#" method="get">
            <input type="tel" id="form_tel" required="required" pattern="^1([3-5]|[7-8])d{9}$"/>
            <input type="submit" id="Go_submit"/>
        </form>
    </body>
<ml>

     
原文地址:https://www.cnblogs.com/ZaraNet/p/9433877.html