The front end of a regular expression commonly used summary

1. The required numbers or letters

/ ^ [0-9a-zA-Z] + $ /

2 must contain at least two letters, numbers, special symbols

/^(((?=.*[0-9])(?=.*[a-zA-Z])|(?=.*[0-9])(?=.*[^\s0-9a-zA-Z])|(?=.*[a-zA-Z])(?=.*[^\s0-9a-zA-Z]))[^\s]+)$/

3. The need to verify the phone number format

/^1[3456789]\d{9}$/

4. Analyzing string only whitespace

/^[\s ]*$/

The need to verify identification number format

/^[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]$/

Use Examples

To verify the composition of Example numbers or letters (as a function of package)

function validUsername (STR) {
   var REG = / ^ [0-9a-zA-the Z] + $ /
   IF (! reg.test (STR)) {
     return 'contains characters other than letters or numbers' 
  } 
  return ' verified by ' 
}

 

Guess you like

Origin www.cnblogs.com/Ky-Thompson23/p/12358145.html