data(){
return{
form: {
uscuName: null, // 学生
uscuPhone: null, // 注册手机号
sex: -1, // 性别
camId: null, // 学籍校区id
campusName: null, // 学籍校区
grade: null, // 年级
courseEducationalType: null, // 学年制
uscuThirdCode: null, // 用户三方库编码
},
}
},
// 使用监听器的格式来控制手机号码只能输入数字
watch:{
'form.uscuPhone':{
handler(newValue, oldValue) {
let oldLength = oldValue ? oldValue.length : 0;
// newValue.replace(/\s/g, '') 去掉空格;
// replace(/[^\d]/g,'') 去掉非数字的字符;
//replace(/(\d{3})(\d{0,4})(\d{0,4})/, '$1 $2 $3') 分割成 3-4-4 格式的手机号;
this.form.uscuPhone =
newValue.length > oldLength ?
newValue.replace(/\s/g, '').replace(/[^\d]/g,'').replace(/(\d{3})(\d{0,4}) (\d{0,4})/, '$1 $2 $3')
: this.form.uscuPhone.trim();
if (this.form.uscuPhone.length > 13) {
// 验证/保存的手机号码,截取13位(其中包含两个空格)
this.form.uscuPhone = this.form.uscuPhone.substring(0,13);
}
this.telphoneTrue = this.form.uscuPhone.length === 13 ? true : false;
},
deep:true
},
}