前端输入框判断集合input

输入框判断

手机号只能是11位并且全部都是数字

			phoneRule(e) {  //电话格式
				let val = e.detail.value.split('');
				let reg = /^[0-9]*$/ ; //判断是否是数字
                                let strNumbr = ''; //结果
				if (val[0] != 1) { //必须是1开头的
					setTimeout(() => {
						this.addData.mobile = '';
					}, 10)
				} else {
					if (val) {
						val.forEach((item, index) => {
							if (reg.test(item)) {
								strNumbr = strNumbr + item;
							}
						});
						setTimeout(() => {
							if(strNumbr.length>11){ //最多11位数
								strNumbr = strNumbr.slice(0,11);
							}
							this.addData.mobile = strNumbr;
						}, 10)
					}
				}
			}
posted @ 2021-12-27 10:22  小泽沐优声  阅读(61)  评论(1编辑  收藏  举报