jaywcjlove / validator.js

:interrobang: Lightweight JavaScript form validation, that had minimal configuration and felt natural to use. No dependencies, support UMD.
https://git.io/validatorjs
551 stars 118 forks source link

可以集成身份证验证吗? #12

Closed stechrayo closed 7 years ago

stechrayo commented 7 years ago

这里是js身份证验证的方案:https://segmentfault.com/a/1190000004437362

stechrayo commented 7 years ago

这里是身份证生成器:http://www.welefen.com/lab/identify/ 。我的js写的很菜

jaywcjlove commented 7 years ago

@stelalae 支持自定义正则

{
  //name 字段
  name: 'cardID',
  // 对应下面验证提示信息
  display:"请你选择性别{{cardID}}|请输入数字",
  //自定义正则`regexp_card_id`
  // 身份证号码为15位或者18位,15位时全为数字,
  // 18位前17位为数字,最后一位是校验位,可能为数字或字符X 
  regexp_card_id:/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/,
  // 验证条件,包括应用自定义正则`regexp_num`
  rules: 'required|regexp_card_id'
}
stechrayo commented 7 years ago

谢谢!