/**
* 手机号规则
* @param { Boolean } required - 是否必填,默认是
* @param { String | Array<String> } trigger - 触发方式,默认 blur,change
*/
export const mobileRule = (required = true, trigger = ['blur']) => {
return [
{
required,
message: '请输入手机号',
trigger
},
{
required,
pattern: /^[1][3,4,5,6,7,8,9][0-9]{9}$/,
message: '请输入标准的手机号',
trigger
}
]
}
/**
* 邮箱规则
* @param { Boolean } required - 是否必填,默认是
* @param { String | Array<String> } trigger - 触发方式,默认 blur,change
*/
export const emailRule = (required = true, trigger = ['blur']) => {
return [
{
required,
message: '请输入邮箱',
trigger
},
{
required,
type: 'email',
message: '请输入正确的邮箱地址',
trigger
}
]
}
/**
* 邮政编码
* @param { Boolean } required - 是否必填,默认是
* @param { String | Array<String> } trigger - 触发方式,默认 blur,change
*/
export const zipCodeRule = (required = true, trigger = ['blur']) => {
return [
{
required,
message: '请输入邮政编码',
trigger
},
{
required,
pattern: /^[[0-9]{6}$/,
message: '请输入正确的邮政编码',
trigger
}
]
}
/**
* 座机号码
* @param { Boolean } required - 是否必填,默认是
* @param { String | Array<String> } trigger - 触发方式,默认 blur,change
*/
export const phoneRule = (required = true, trigger = ['blur']) => {
return [
{
required,
message: '请输入电话号码',
trigger
},
{
required,
pattern: /^0\d{2,3}-(\d{7,8})$/,
message: '请输入正确的电话号码',
trigger
}
]
}