UNPKG

front-standard-utils

Version:
40 lines (36 loc) 897 B
/** * * @desc 判断是否为手机号 * @param str * @returns Boolean */ export const isPhoneNum = (str: string) => { return /^(\+?0?86\-?)?1[3456789]\d{9}$/.test(str) } /** * * @desc 判断是否为URL地址 * @param str url地址 * @returns Boolean */ export const isUrl = (str: string) => { return /[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/i.test(str); } /** * * @desc 判断是否为邮箱 * @param str * @returns Boolean */ export const isEmail = (str: string) => { return /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(str); } /** * * @desc 判断是否为身份证号 * @param str * @returns Boolean */ export const isIdCard = (str: string) => { return /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/.test(str) }