zoukankan      html  css  js  c++  java
  • js中的正则表达式使用

     1 function myValid() {
     2     var errorMsg = "";
     3     var res = true;
     4     //拿到要验证的值.
     5     var receiveName = $("#receiveName").val();//姓名
     6     var receiveMobile = $("#tMobile").val();//手机号
     7     var validCode = $("#validCode").val();//验证码
     8 
     9     var regName = /^[u4e00-u9fa5]{2,4}$/;//验证姓名
    10     var regMobile = /^1[3|4|5|7|8][0-9]d{8}$/;//验证手机
    11     var regCode = /^d{4}$/;//验证码
    12     if (!regName.test(receiveName)) {
    13     errorMsg += "姓名格式不正确;
    
    ";
    14     res = false;
    15     }
    16     if (!regMobile.test(receiveMobile)) {
    17     errorMsg += "手机号格式不正确;
    
    ";
    18     res = false;
    19     }
    20     if (!regCode.test(validCode)) {
    21     errorMsg += "请输入4位的数字验证码;
    
    ";
    22     res = false;
    23     }
    24     if (!res) {
    25     $.ligerDialog.error(errorMsg, "错误提示");
    26     }
    27     return res;
    28 }

    贪婪模式和正则匹配

    try {
                str = "<p>abcdefg</p><p>abcdefghijkl</p>";
    
                re1 = str.match(/<p>[Ww]+?</p>/ig);
                alert("非贪婪模式:
    
    1:" + re1[0] + "
    2:" + re1[1]);
    
                re1 = str.match(/<p>[Ww]+</p>/ig);
                alert("贪婪模式:
    
    " + re1);
    
                re1 = str.match(/<p>(.+?)</p>/i);
                alert("非贪婪模式,且不要标记:
    
    1:" + re1[1]);
    
                re1 = str.match(/<p>(.+)</p>/i);
                alert("贪婪模式,且不要标记:
    
    " + re1[1]);
            } catch (e) {
                alert(e.description);
            }
    

      

    欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。如果感觉对您有用,请点击推荐。您的支持,是我的动力!
  • 相关阅读:
    POJ 2506 Tiling
    POJ 2586 Y2K Accounting Bug
    POJ 2965 The Pilots Brothers' refrigerator (DFS)
    POJ 2499 Binary Tree
    POJ 3006 Dirichlet's Theorem on Arithmetic Progressions (素数)
    beautifulsoup 基本语法 含class属性查找小技巧class_
    xlrd库的使用
    pytest框架 里 fixture 参数化的方法
    ddt数据驱动
    mac电脑 pip安装包后 撞到了系统python里面的解决方法
  • 原文地址:https://www.cnblogs.com/ICE_Inspire/p/4986655.html
Copyright © 2011-2022 走看看