微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

宜人贷项目里-----正则匹配input输入月份规则

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();    }}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐