Java regular expression matching phone format _java

Source: Internet
Author: User

As we all know, regular expressions are a specification that can be used for pattern matching and substitution. A regular expression is a literal pattern consisting of ordinary characters (such as characters A through Z) and special characters (metacharacters) that describe one or more strings to be matched when finding the body of the text. A regular expression is used as a template to match a character pattern with the string being searched for.

/**
   * Mobile phone Number: There are 27 kinds of mobile phone number in the country.
   * Mobile has 16 number of segments: 134, 135, 136, 137, 138, 139, 147, 150, 151, 152, 157, 158, 159, 182, 187, 188. 147, 157, 188 are 3G, and others are 2G segments.
   * China Unicom has 7 kinds of paragraph number: 130, 131, 132, 155, 156, 185, 186. 186 of them are 3G (WCDMA), and the rest are 2G segments.
   * Telecommunications has 4 segments: 133, 153, 180, 189. 189 of which is 3G (CDMA2000), and segment 133th is used primarily as a wireless network card number.
   * 150, 151, 152, 153, 155, 156, 157, 158, 1599;
   * 130, 131, 132, 133, 134, 135, 136, 137, 138, 1390;
   * 180, 182, 185, 186, 187, 188, 1897;
   * 13, 15, 183, a total of 30 segments, 154, 181, 183, 184 for the time being, plus 147 altogether 27.
   * *
  Private Boolean Telcheck (String tel) {pattern
    p = pattern.compile ("^" (13\\d{9}$) | ( 15[0,1,2,3,5,6,7,8,9]\\d{8}$) | (18[0,2,5,6,7,8,9]\\d{8}$) | (147\\d{8}) $) ");
    Matcher m = p.matcher (tel);
    return m.matches ();
  }

Java Regular Expression validation format (mailbox, phone number)

Package com.firewolf.utils;
Import Java.util.regex.Matcher;
Import Java.util.regex.Pattern; 
    /** * Use regular expressions to validate input formats * @author liuxing * * */public class Regexvalidateutil {public static void main (string[] args) {
    System.out.println (Checkemail ("14_8@qw.df"));
  System.out.println (Checkmobilenumber ("071-3534452")); /** * Verify Mailbox * @param email * @return/public static Boolean checkemail (String email) {Boolean flag
    = false; try{String check = "^" ([a-z0-9a-z]+[-|_|\\.]?) +[a-z0-9a-z]@ ([a-z0-9a-z]+ (-[a-z0-9a-z]+)/\.)
        +[a-za-z]{2,}$ ";
        Pattern regex = pattern.compile (check);
        Matcher Matcher = regex.matcher (email);
      Flag = Matcher.matches ();
      }catch (Exception e) {flag = false;
  return flag; 
    /** * Verify mobile phone number * @param mobiles * @return/public static Boolean Checkmobilenumber (String mobilenumber) {
    Boolean flag = false; try{Pattern regex = Pattern.compile ("^" ((13[0-9)) | ( 15 ([0-3]| [5-9]) | (18[0,5-9]) \\D{8}) | (0\\d{2}-\\d{8}) |
        (0\\d{3}-\\d{7}) $ ");
        Matcher Matcher = Regex.matcher (Mobilenumber);
      Flag = Matcher.matches ();
      }catch (Exception e) {flag = false;
  return flag; }
}

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.