Common form validation RegExp

  1. Phone number check
  2. ID card

Phone number check

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

ID card

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]$/;

reference:

  1. chinaMobiePhoneNumberRegExp
  2. validator.js
  3. ID check
  4. Identity validation rules

Guess you like

Origin www.cnblogs.com/rosendolu/p/11615881.html