UNPKG

abbott-methods

Version:

abbott,methods,method,functions,function

28 lines (27 loc) 886 B
import { formatMobile } from '../format/formatMobile' 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 vPhone = (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 (formatMobile(validateValue) || formatTelephone(validateValue)) { callback() } else { callback(new Error(`${field}格式不正确`)) } } } }