• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Rgzs
博客园    首页    新随笔    联系   管理    订阅  订阅
正则验证身份证、数字、数字字母
// 对不是必填属性的验证(手机号的验证)
export const matchPhone = (control: FormControl): { [key: string]: boolean } => {
if (control.value == null || '' === control.value) {
return null;
}
const tell = control.value;
if (!(/^1(3|4|5|7|8|9)\d{9}$/.test(tell))) {
return {nomatch: true};
} else {
return null;
// 这里一定是null
}
};
// 身份证正则校验
export const matchSfzh = (control: FormControl): { [key: string]: boolean } => {
const sfzh = control.value;
if (!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(sfzh))) {
return {nomatch: true};
} else {
return null;
// 这里一定是null
}
};
// 数字正则校验
export const matchNumber = (control: FormControl): { [key: string]: boolean } => {
if (control.value == null || '' === control.value) {
return null;
}
const ex = control.value;
if (!(/^[0-9]*$/.test(ex))) {
return {nomatch: true};
} else {
return null;
// 这里一定是null
}
};
// 英文字母校验
export const matchWord = (control: FormControl): { [key: string]: boolean } => {
if (control.value == null || '' === control.value) {
return null;
}
const ex = control.value;
if (!(/^[A-Za-z]+$/.test(ex))) {
return {nomatch: true};
} else {
return null; // 这里一定是null
}
};
// 英文数字组合正则校验
export const matchNumberAndWord = (control: FormControl): { [key: string]: boolean } => {
if (control.value == null || '' === control.value) {
return null;
}
const ex = control.value;
if (!(/^[A-Za-z0-9]+$/.test(ex))) {
return {nomatch: true};
} else {
return null; // 这里一定是null
}
};
posted on 2022-03-25 10:18  飄落的葉子  阅读(184)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3