JAVA Regular expressions to determine whether the phone number is legal __java

Source: Internet
Author: User
First we need to figure out how many number sections have been opened now, and the country numbers are allocated as follows:
Mobile: 134, 135, 136, 137, 138, 139, 150, 151, 157 (TD), 158, 159, 187, 188
Unicom: 130, 131, 132, 152, 155, 156, 185, 186
Telecommunications: 133, 153, 180, 189, (1349 health)

The rest is to write a regular expression to match, as follows:

Package com.example.offline;
Import Java.util.regex.Matcher;

Import Java.util.regex.Pattern; /** * * * @author Fx_sky * */public class Phonetest {/** * @param args/public static void Main (string[) arg
		s) {//TODO auto-generated method stub String telnum = "10086";
		Boolean flag = Ismobiphonenum (Telnum);
		
		System.out.println ("Telnum" +telnum + "Ismobiphonenum" +flag);
		Telnum = "13611503575";
		Flag = Ismobiphonenum (Telnum);
	System.out.println ("Telnum" +telnum + "Ismobiphonenum" +flag); /** * Universal Judgment * @param telnum * @return/public static Boolean Ismobiphonenum (String telnum) {string regex = "^ ((13[0-9]) | (15[0-9]) | (18[0-9])
        \\d{8}$ ";
        Pattern p = pattern.compile (regex,pattern.case_insensitive);
        Matcher m = P.matcher (Telnum);
	return m.matches (); /** * More rigorous judgment * @param mobiles * @return/public static Boolean Ismobilenum (String telnum) {pattern p = P Attern.compile ("^ (13[0-9]) |" ( 15[^4,\\D]) | (18[0,5-9]) \\d{8}$ ");
		Matcher m = P.matcher (Telnum);
	return m.matches ();
 }
}

Here are two methods of judging, the first one is more general, the second method is more strict than the first method, and the number 154th is removed; You can choose according to the project.




Related Article

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.