• HTML使用正则验证


    制作HTML前台用户验证等,需要对用户名或者密码进行验证,这时使用正则表达式能够精确地对text进行限制。

    具体在HTML中的运用代码如下:

    转自 https://blog.csdn.net/weixin_43524620/article/details/83820989

    //首先创建一个input框 id为id手机号
    <input type="text" name="tel" id="id"><br>
    
    //创建一个button,引用下面的fun()
    <input type="button" οnclick="fun()" value="验证"><br>
     
    //引用jq文件
    <script src="{{asset('js')}}/jquery.min.js"></script>
    
    
    <script>
    //这里创建了点击事件
        function fun() {
    //获取到id为id 的val值
           var tel = $('#id').val();
            //alert(tel);
    //这里设置正则表达式,放在下划线之间
    //^是指从头开始 $到哪里结束 1代表第一位必须是1 [345]第二位必须是345 [0-9]{9}指的是后九位必须是0-9之间的数字
            var res =/^1[345][0-9]{9}$/;
            //res是正则表达式 .test() 验证正则  括号填写需要验证的值
            if(res.test(tel)){
                alert(1);
            }else{
                alert(2);
            }
        }
    </script>
  • 相关阅读:
    模块 hashlib模块
    设计模式
    类中双下方法
    工作小结 常见定制类
    python collections模块
    启动脚本
    anaconda镜像
    理解python的可变参数
    使用spark
    python 异常处理
  • 原文地址:https://www.cnblogs.com/ccwx/p/12893900.html
Copyright © 2020-2023  润新知