Regular expressions commonly used in java

Regular expressions commonly used in java:

In the program, we generally use JS code in the foreground to verify the user's input content. After the verification is passed, in the background, we need to perform secondary verification on the user's input content to ensure that the data is not changed during transmission. . When we match the content with regular expressions in the background, we need to use the Matcher method.

  • The purpose of the Pattern class is to create a matching pattern after compiling the regular expression.
  • The Matcher class uses the pattern information provided by the Pattern instance to match regular expressions
// The background needs to verify the uploaded parameters again
 if (! Pattern.matches ( "^1[1-9] \\ d{9}$" , phone)) {
    retMap.put(Constants. ERROR_MESSAGE , " Please enter the correct mobile number " ) ;
     return retMap ;
 }

Here is a verification of the background data.

Some regular expressions applied in java:

Mainland China mobile phone number format
In js code: ^1[1-9]\d{9}$
In java code: ^1[1-9]\\d{9}$

Password characters can only use numbers and uppercase and lowercase English Letter
^[0-9a-zA-Z]+$

Password should contain both English or numbers
^(([a-zA-Z]+[0-9]+)|([0-9]+[a-zA -Z]+))[a-zA-Z0-9]*

Chinese format verification
Js code: [^\x00-\x80]
Java code: [\\u4e00-\\u9fa5]+

ID card number formatID
card number Rules: ID card number is 15 or 18 digits, 15 digits are all digits, the first 17 digits of 18 digits are digits, and the last digit is the check digit, which may be digits or characters X
Regular expression: (^\d{ 15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)





Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326078897&siteId=291194637