The example in this article describes the regular tool class implemented in java. Share it with everyone for your reference. The details are as follows:
The regular tool class implemented here is suitable for: regular phone numbers, email addresses, QQ numbers, QQ passwords, and mobile phone numbers
The java code is as follows:
package com.zhanggeng.contact.tools;/** * RegexTool is used to regex the string, such as: phone, qq, password, email. * * @author ZHANGGeng * @version v1.0.1 * @since JDK5.0 * */public class RegexTool { /** * * @param phoneNum This method is called when the incoming parameter is just a phone number* @return If the match is correct, return true, else return else */ //If the phone number is passed in, perform regular matching on the phone number public static boolean regexPhoneNumber(String phoneNum){ //Phone number matching result boolean isPhoneNum_matcher = phoneNum.matches ("1[358]//d{9}"); //If isPhoneNum_matcher is true, return true, else return false if(isPhoneNum_matcher) return true; return false; } /** * * @param email This method is called when the incoming parameter is just an email address* @return If the match is correct, return true, else return false */ // If the email address is passed in, regular matching will be performed on the email address public static boolean regexEmailAddress(String email){ //Email matching result boolean isEmail_matcher = email.matches("[a-zA-Z_0-9]+@[a-zA-Z0-9]+(//.[a-zA-Z]{2,}){1,3}"); //If isEmail_matcher value is true, return true, else return false if(isEmail_matcher) return true; return false; } /** * * @param phoneNum Incoming phone number* @param email Incoming email address * @return If the match is correct, return true , else return false */ public static boolean regexEmailAddressAndPhoneNum(String phoneNum, String email){ //Phone number matching result boolean isPhoneNum_matcher = phoneNum.matches("1[358] //d{9}"); //Email matching result boolean isEmail_matcher = email.matches("[a-zA-Z_0-9]+@[a-zA-Z0-9]+(//.[a-zA-Z]{2,}){1,3}"); //matcher value is true, then return true, else return false if(isEmail_matcher && isPhoneNum_matcher){ return true; } return false; } /** * * @param qqNum Incoming QQ * @return If the match is correct, return true, else return false */ public static boolean regexQQNumber(String qqNum){ //QQ number matching result boolean isQQNum_matcher = qqNum.matches("[1-9]//d {2,11}"); if(isQQNum_matcher) return true; return false; } /** * * @param pwd Password is passed in * @return If the match is correct and the password rules are met, return true, else return false */ public static boolean regexPassWord(String pwd){ //Password matching result boolean isPassWord_matcher = pwd.matches("[0-9a -zA-Z_@$@]{6,12}"); if(isPassWord_matcher) return true; return false; }}I hope this article will be helpful to everyone’s Java programming.