I have write a custom validator for phone and use it like this
html
<template>
<input type="text" name="username" class="username" v-validate="'required|email|phone'">
</template>
<script>
import { MobileValidate } from '@/validates/MobileValidates'
Validator.extend('phone', MobileValidate);
</script>
phone validate
const MOBILEREG = /^((1[3578][0-9])+\d{8})$/;
export const MobileValidate = {
getMessage(field, args) {
return 'phone is wrong';
},
validate(value, args) {
console.log(MOBILEREG.test(value), value)
return MOBILEREG.test(value);
}
};
I want to validate the username is email or phone number, but it seems not work. How can I solve this problem?