zoukankan      html  css  js  c++  java
  • 宜人贷项目里-----正则匹配input输入月份规则

    在标签上可以直接进行校验如下,如果只调数字键盘type=number不好用可以用type=tel

    <input name="creditDate" oninput="value = value.replace(/[^d{2}/{1}d{2}$]/ig,'')" @keyup="changeVal" v-model="getDate" type="text" placeholder="月/年">


    changeVal(e){
    let $val = e.currentTarget.value;
    e.currentTarget.value = $val.replace(/[^d{2}/{1}d{2}$]/ig,'')
    let inputVal = e.currentTarget.value
    this.all = true;
    if(/^[2-9]/ig.test(inputVal)){
    e.currentTarget.value = '0'+inputVal
    this.all1 = true;
    }
    if(/^[1]/ig.test(inputVal)){
    e.currentTarget.value = e.currentTarget.value.replace(/^1[^0-2|/]/ig,'1')
    this.all1 = true;
    }
    if(/^[0]/ig.test(inputVal)){
    e.currentTarget.value = e.currentTarget.value.replace(/^0[^1-9|/]/ig,'0')
    this.all1 = true;
    }
    if(e.currentTarget.value.length == 2 && e.keyCode !=8 && !/^1//ig.test(e.currentTarget.value)){
    e.currentTarget.value = e.currentTarget.value + '/'
    this.all2 = true;
    }
    if(e.currentTarget.value.length >= 5){
    e.currentTarget.value = e.currentTarget.value.substr(0,5)
    this.all3 = true;
    }
    e.currentTarget.value = e.currentTarget.value.replace(/[^d{2}/{1}d{2}$]/ig,'')
    this.getDate = e.currentTarget.value
    if(this.all && this.all1 && this.all2 && this.all3){
    this.submitBtnFrag();
    }
    }
  • 相关阅读:
    优化总结文章链接
    帧同步、状态同步
    ecs
    AStarPathFinding
    unity 热更方案对比
    C#数据类型
    JavaScript基础
    CSS中margin和padding的区别
    css选择器
    hadoop中使用shell判断HDFS文件是否存在
  • 原文地址:https://www.cnblogs.com/chaoyuehedy/p/9405729.html
Copyright © 2011-2022 走看看