Android Regular Expression verifies mobile phone numbers, names (including ethnic minorities), ID card numbers, and android Regular Expressions
The new features in recent projects require verification of mobile phone numbers, names, ID card numbers, and other information. The best way is to use regular expressions for verification and check some information online, write these tools and methods.
1. Verify the mobile phone number
Rule: the first digit can only be 1, the second digit is a number in 3-8, and the third digit is any number.
/*** Mobile phone number verification, 1st bits: 1; 2nd bits: {3, 4, 5, 6, 7, 8} Any number; 3-11 bits: 0-9 arbitrary number * @ param value * @ return */public static boolean isTelPhoneNumber (String value) {if (value! = Null & value. length () = 11) {Pattern pattern = Pattern. compile ("^ 1 [3 | 4 | 5 | 6 | 7 | 8] [0-9] \ d {8} $"); Matcher matcher = pattern. matcher (value); return matcher. matches ();} return false ;}
2. Verify the name here. You can enter anything in the input box, but this method is called when you click the Verify button.
The verification rules are as follows: the name consists of Chinese characters or Chinese characters plus "•" and "·", and only one "vertex" can be entered, the "point" cannot be in the first or end position. It is verified only between Chinese characters.
/*** Verify whether the input name is "Chinese" or "·" */public static boolean isLegalName (String name) {if (name. contains ("·") | name. contains ("•") {if (name. matches ("^ [\ u4e00-\ u9fa5] + [· •] [\ u4e00-\ u9fa5] + $") {return true ;} else {return false ;}} else {if (name. matches ("^ [\ u4e00-\ u9fa5] + $") {return true ;}else {return false ;}}}
3. Verify the ID card number
Verify ID card number
The rule is: it consists of 15 digits or 18 digits (17 digits plus "x"). There is nothing to say about 15 pure digits, it can be an 18-digit numeric, or a 17-digit numeric plus "x"
/*** Verify that the entered id card number is valid */public static boolean isLegalId (String id) {if (id. toUpperCase (). matches ("(^ \ d {15} $) | (^ \ d {17} ([0-9] | X) $ )")) {return true;} else {return false ;}}
The above regular expression is used to verify the result. true and false are returned.