匹配中文: [\u4e00-\u9fa5]
英文字母: [a-zA-Z]
数字: [0-9]
匹配中文,英文字母和数字及_: ^[\u4e00-\u9fa5_a-zA-Z0-9]+$
匹配手机号如下:
var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
if (!myreg.test(mobile)) {
wx.showToast({
title: '手机号有误!',
icon: 'success',
duration: 1500
})
return false;
}
return true;
匹配输入的字符为汉字如下:
var testTitle = /^[\u4e00-\u9fa5]+$/;
if(!this.data.title){
wx.showToast({
title: '请输入标题',
icon:'none',
duration:2000
})
return false;
}
if(!testTitle.test(this.data.title)){
wx.showToast({
title: '标题只能输入汉字,请重新输入',
icon:'none',
duration:2000
})
return false;
}