UNPKG

abbott-methods

Version:

abbott,methods,method,functions,function

32 lines (31 loc) 966 B
import { formatCellphone } from '../format/formatCellphone' import { typeEmpty } from '../type/typeEmpty' /** * @desc 验证是否手机号码格式 * @param {boolean} required * @param {String} validateValue * @param {*} callback * @param {String} field * @param {String} action */ export const vCellphone = (required: boolean, validateValue: string, callback: any, field: string = '手机号码', action: string = '填写'): void => { if (!required && !validateValue) { callback() } else { const number = 11 if (typeEmpty(validateValue)) { action = action || '填写' callback(new Error(`${field}必须${action}`)) } else { if (formatCellphone(validateValue)) { if (validateValue.length !== number) { callback(new Error(`${field}的长度为${number}个字符`)) } else { callback() } } else { callback(new Error(`${field}格式不正确`)) } } } }