The code is as follows:
1 Public Static Booleanisemail (String email) {2String str = "^ ([a-za-z0-9_\\-\\.] +) @ ((\\[[0-9]{1,3}\\. [0-9] {1,3}\\. [0-9] {1,3}\\.) | ([a-za-z0-9\\-]+\\.) +)) ([a-za-z]{2,4}| [0-9] {1,3}) (\\]?) $";3Pattern p =pattern.compile (str);4Matcher m =p.matcher (email);5 returnm.matches ();6 }7 8 Public Static Booleanisphonenumbervalid (String phonenumber) {9 BooleanIsValid =false;Ten OneString expression = "((^ (13|15|18) [0-9]{9}$) | ( ^0[1,2]{1}\\d{1}-?\\d{8}$) | (^0[3-9] {1}\\d{2}-?\\d{7,8}$) | (^0[1,2]{1}\\d{1}-?\\d{8}-(\\d{1,4}) $) | (^0[3-9]{1}\\d{2}-\\d{7,8}-(\\d{1,4}))) "; ACharsequence Inputstr =PhoneNumber; - -Pattern pattern =pattern.compile (expression); theMatcher Matcher =Pattern.matcher (INPUTSTR); - - if(Matcher.matches ()) { -IsValid =true; + } - + returnIsValid; A}
Java Verification phone number and mailbox