package org.mo.open.common.util;/** * Check form tools * * @author moziqi * */public final class regexvalidateutil {private regexvalidateutil () {}private static boolean flag = false;private static String regex = "";/** * verify QQ number * * @param QQ * @return * /PUBLIC STATIC BOOLEAN CHECKQQ (STRING QQ) {String regex = "^\\s*[.0-9" {5,10}\\s*$ "; Return check (Qq, regex);} /** * Verify mobile number * * Mobile number segment: 139, 138, 137, 136, 135, 134, 150, 151, 152, 157, 158, 159, 182, 183, 187, 188, 147 * unicom number segment: 130, 131, 132, 136, 185, 186, 145 Telecom number segment: 133, 153, 180, 189 * * @param cellphone * @return */public static boolean checkcellphone (String cellphone) {String regex = "^ (13[0-9) | ( 14[5|7]) | (15 ([0-3]|[ 5-9])) | (18[0,5-9])) \\d{8}$ "; Return check (Cellphone, regex);} /** * Verifying landline numbers * * @param telephone * @return */public Static boolean checktelephone (string telephone) {String regex = "^ (0\\d{2}- \\d{8} (-\\d{1,4})?) | (0\\d{3}-\\d{7,8} (-\\d{1,4})?) $ "; Return check (Telephone, regex);} /** * Verify Fax number * * @param fax * @return */public static boolean checkfax (string fax) {String regex = "^ (0\\d{2}-\\d{8} (-\\d{1,4})?) | (0\\d{3}-\\d{7,8} (-\\d{1,4})?) $ "; Return check (Fax, regex);} /** * Verification Email * * @param email * @return */public static boolean checkemail (string email) {String regex = "^\\s*\\w+ (?: \ \. {0,1} [\\w-]+) *@[a-za-z0-9]+ (?: [-.] [a-za-z0-9]+] *\\. [a-za-z]+\\s*$]; Return check (Email, regex);} /** *&nbSP; Verify non-empty * * @param notEmputy * @return */public static Boolean checknotemputy (string notemputy) {regex = "^\\s*$"; Return check ( Notemputy, regex) ? false : true;} Private static boolean check (String str, string regex) {try {flag = str.matches (regex);} catch (Exception e) {flag = false;} Return flag;}}
Java validation form, regular expression