1 /**2 * Verify the phone number.3 * 4 * @paramPhone the phone5 * @returntrue, if successful6 */7 Public Static BooleanIsphone (String phone) {8 if(Stringutils.isblank (phone)) {9 return false;Ten } OneString regex = "^[1][3,4,5,8][0-9]{9}$"; APattern p =pattern.compile (regex); -Matcher m =p.matcher (phone); - returnm.matches (); the}
1 /**2 * Verify that the ID number is legal (only 18 bits are verified).3 *4 * @paramIdcard the ID card5 * @returntrue, if is ID card6 */7 Public Static BooleanIsidcard (String idcard) {8String regex = "((1[1-5) | ( 2[1-3]) | (3[1-7]) | (4[1-6]) | (5[0-4]) | (6[1-5]) |71| (8[12]) |91) \\d{4} ((19\\d{2} (0[13-9]|1[012]) (0[1-9]|[ 12]\\D|30)) | (19\\d{2} (0[13578]|1[02]) 31) | (19\\d{2}02 (0[1-9]|1\\d|2[0-8)) | (19 ([13579][26]|[ 2468][048]|0[48]) (0229)) (\\d{3}) (\\d| x|x)) ";9 int[] Factorarray =New int[]{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};Tenstring[] Paritybit =Newstring[]{"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"}; Onestring[] IDArray =NewString[18]; A intIntstrlen =idcard.length (); -String Idstr =Idcard; - intsum = 0; the - //Regular verify that the ID card format is correct -Pattern pattern =pattern.compile (regex); -Matcher Matcher =Pattern.matcher (idcard); + if(!matcher.matches ()) { - return false; + } A at //Verify that the ID number algorithm is legal - for(inti = 0; i < Intstrlen; i + +){ -Idarray[i] = Idstr.charat (i) + ""; - if(I < (intStrLen-1)){ -Sum + = factorarray[i] *Integer.parseint (Idarray[i]); - } in } - if(!paritybit[(sum%)].equalsignorecase (idarray[intstrlen-1])){ to return false; + } - return true; the}
Java Regular validation