abbott-methods
Version:
abbott,methods,method,functions,function
27 lines (26 loc) • 811 B
text/typescript
import { formatTelephone } from '../format/formatTelephone'
import { typeEmpty } from '../type/typeEmpty'
/**
* @desc 验证是否手机号码或固定电话格式
* @param {boolean} required
* @param {String} validateValue
* @param {*} callback
* @param {String} field
* @param {String} action
*/
export const vTelephone = (required: boolean, validateValue: string, callback: any, field: string = '固定电话', action: string = '填写'): void => {
if (!required && !validateValue) {
callback()
} else {
if (typeEmpty(validateValue)) {
action = action || '填写'
callback(new Error(`${field}必须${action}`))
} else {
if (formatTelephone(validateValue)) {
callback()
} else {
callback(new Error(`${field}格式不正确`))
}
}
}
}