1.手機(jī)號
?const?reg?=?/^[1][3,4,6,5,7,8,9][0-9](\*|[0-9]){4}[0-9]{4}$/;
2.郵箱
const?reg?=?/^([a-zA-Z]|[0-9])(\w|-)+@[a-zA-Z0-9]+(\.([a-zA-Z]+))+$/;
3.身份證號
?const?reg?=?/(^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$)|(^\d{6}(18|19|20)\d{2}(0[1-9]|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)$)/;
4.中文姓名
const?reg?=?/^([\u4e00-\u9fa5]{1,}·{0,})([\u4e00-\u9fa5]{1,})$/;
5.網(wǎng)址
const?reg?=?/^(((ht|f)tps?):\/\/)?[\w-]+(\.[\w-]+)+([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?$/;
6.郵政編碼 (可輸入任意數(shù)字 不能輸入6個(gè)0)
const?reg?=?/(?!0{6})(^\d+$)/??
********************************************************************************************************
結(jié)合elementui使用方式
export?function?validatePhone(rule:?any,?value:?string,?callback:?any)?{
????const?reg?=?/^[1][3,4,6,5,7,8,9][0-9](\*|[0-9]){4}[0-9]{4}$/;
????if?(value?===?''?||?value?===?undefined?||?value?===?null)?{
????????callback();
????}?else?{
????????if?(!reg.test(value)?&&?value?!==?'')?{
????????????callback(new?Error('請輸入正確的電話號碼'));
????????}?else?{
????????????callback();
????????}
????}
}
rules: {
? ? ? ? ? phone: [
? ? ? ? ? ? { validator: ?validatePhone, trigger: 'blur' }
? ? ? ? ? ],
}