まず、新しいディレクトリチェックを作成し、このディレクトリにindex.jsファイルを作成します
const check = {
telphone(data) {
if(!(/^1[3456789]\d{9}$/.test(data))){
uni.showToast({
title: "手机号码不正确",
icon:'none'
});
return false;
}
return true
},
password(data) {
if(data.length<6) {
uni.showToast({
title: "密码长度不能小于6位",
icon:'none'
});
return false;
}
return true
}
}
export default check;
main.jsにファイルをインポートし、インスタンスを作成します
import check from './check/index.js'
Vue.prototype.check=check
コンポーネントでの使用
if(this.check.telphone(this.telphone) == false){
return}
if(this.check.password(this.password) == false){
return}