Java-implemented regular tool class _java

Source: Internet
Author: User

The examples in this article describe the regular tool classes for Java implementations. Share to everyone for your reference. Specifically as follows:

The regular tool class implemented here is applicable to: regular telephone number, mailbox, QQ number, QQ password, mobile phone number

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 phonen When UM incoming arguments are just a phone number, call this method * @return If the match is correct, return true, else return else///If the phone number is passed in, then the phone number is matched public St atic boolean regexphonenumber (String phonenum) {//Phone number match result Boolean isphonenum_matcher = Phonenum.matches ("1[358]\\
    D{9} ");
    Return True if Isphonenum_matcher is true, or else return False if (Isphonenum_matcher) return true;
  return false; /** * * * @param email incoming parameter is only a mailbox address, call this method * @return If the match is correct, return true, else return false////If it comes in is a mailbox address, a regular match is made to the mailbox public static Boolean regexemailaddress (String email) {//Mailbox matching result boolean Isemail_matcher = email . Matches ("[A-za-z_0-9]+@[a-za-z0-9]+ (\\.[
    A-za-z]{2,}) {1,3} "); return TRUE if Isemail_matcher value is 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 Fals E/public static Boolean Regexemailaddressandphonenum (string phonenum, string email) {//Phone number match result Boolean I
    Sphonenum_matcher = Phonenum.matches ("1[358]\\d{9}"); Mailbox Match 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, return true, else return False if (Isemail_matcher && isphonenum_matcher) {R
    Eturn true;
  return false; /** * * * @param qqnum incoming QQ * @return If the match is correct, return true, else return false */public static Boolean Reg
    Exqqnumber (String qqnum) {//qq number matches the result boolean isqqnum_matcher = Qqnum.matches ("[1-9]\\d{2,11}");
    if (Isqqnum_matcher) return true;
  return false; /** * * * @param pwd Incoming password * @return If the match is correct, meetPassword rule, return true, else return false */public static Boolean Regexpassword (String pwd) {//Password match result Boolean isPa
    Ssword_matcher = Pwd.matches ("[0-9a-za-z_@$@]{6,12}");
    if (Ispassword_matcher) return true;
  return false;

 }
}

I hope this article will help you with your Java programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.