UNPKG

pgh-common-utils

Version:

A collection of utility functions for TypeScript.

13 lines (12 loc) 427 B
// 常用正则规则 export const RegexRules = { mobile: /^1[3-9]\d{9}$/, // 手机号 email: /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/, // 邮箱 idCard: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/, // 身份证 url: /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/i, chinese: /^[\u4e00-\u9fa5]+$/, // 纯中文 }; // 验证函数 export function validate(str, type) { return RegexRules[type].test(str); }