• 正则验证


    构造函数正则

    var exp = '/^1[3456789]\d{9}$/'
    
    new RegExp(exp.slice(1,-1)).test(18086440878)

    需要注意的是创建字符串变量时会把一个去掉,需要用两个\

    找出一串字符串中出现(或者连续出现)最多的字符

    function findSameStrs(s) {
     if(typeof s !== "string") return '';
     var str = s;
      //下面对乱的字符排序,如果题目要求”连续出现”最多字符的话,不用写
      str = s.split('').sort((a,b)=>a.localeCompare(b)).join('');
    
      var reg = /(w)1+/g;
      var arr = str.match(reg);//捕获匹配的字符
    if(arr){
      // 将正则匹配到的结果继续按照字符串的长度排序(从大到小)
        arr.sort((a,b)=>b.length - a.length);
        console.log("出现次数最多的字符是:" + arr[0][0] + "出现:" + arr[0].length + "次")
      }else{
      // 如果正则没有匹配到的,则表示该字符串没有重复出现的字符,默认打印字符串第一位
        console.log("出现次数最多的字符是:" + s[0], "出现: 1次")
      }
    }
    onkeyup="this.value= this.value.match(/d+(.d{0,2})?/) ? this.value.match(/d+(.d{0,2})?/)[0] : ''"
    onkeyup="this.value=this.value.replace(/D/g,'')"
    onkeyup="this.value=this.value.replace(/D|^0/g,'')"
    $("#Price").textbox('textbox').bind('keyup', function (e) {
    $("#Price").textbox('setValue', $(this).val().match(/d+(.d{0,2})?/) ? $(this).val().match(/d+(.d{0,2})?/)[0] : '' );
    });
  • 相关阅读:
    python中的反射
    ZOJ 3827 Information Entropy 水
    我的软考之路(七)——数据结构与算法(5)之查找
    nginx.conf 集群完整配置
    恼人的函数指针(二)
    C语言100个经典的算法
    spring事务心得积累
    Vue报错:OPTIONS 405 Method Not Allowed以及CORS跨域错误
    IDA脚本dump内存的示例
    lightProxy
  • 原文地址:https://www.cnblogs.com/liufeiran/p/13427493.html
Copyright © 2020-2023  润新知