当前位置: 首页 > Web前端 > vue.js

js经常有正则表达式

时间:2023-03-31 17:11:11 vue.js

vue限制姓名只能输入32位汉字,电话号码11位,验证码6位watch:{'bindForm.name'(val){letpattern=/[^\u4e00-\u9fa5]+/this.bindForm.name=val.replace(pattern,'')if(val.length>32){this.bindForm.name=val.substring(0,32)}this.checkIsComplete()},'bindForm.phone'(val){if(val.length>11){this.绑定表单。电话=值。substring(0,11)}这个。checkIsComplete()},'绑定表格。code'(val){if(val.length>6){this.bindForm.code=val.substring(0,6)}this.checkIsComplete()},}获取地址栏参数functiongetQueryString(name){varreg=newRegExp('(^|&)'+name+'=([^&]*)(&|$)','i')varreg_rewrite=newRegExp('(^|/)'+name+'/([^/]*)(/|$)','i')varr=window.location.search.substr(1).match(reg)varq=window.location.pathname.substr(1).match(reg_rewrite)if(r!=null){returnunescape(r[2])}elseif(q!=null){返回unescape(q[2])}else{返回null}}