常用表单校验RegExp

  1. 手机号校验
  2. 身份证

手机号校验

const regExp = /^(?:\+?86)?1(?:3\d{3}|5[^4\D]\d{2}|8\d{3}|7(?:[35678]\d{2}|4(?:0\d|1[0-2]|9\d))|9[189]\d{2}|66\d{2})\d{6}$/
// example 
regExp.test(15878673234) // true

身份证

const regExp = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;

参考:

  1. chinaMobiePhoneNumberRegExp
  2. validator.js
  3. 身份证校验
  4. 身份证校验规则

猜你喜欢

转载自www.cnblogs.com/rosendolu/p/11615881.html