Java Phone number removal IP number, +86__java

Source: Internet
Author: User
Tags ip number

The recent project needs to filter the phone number, remove the IP number ("1790", "1791", "1793", "1795", "1796", "1797", "1799"), +86, and other prefixes, share with you.

Package com.example.offline; public class Trimnumbertest {private static final string[] IPPFXS4 = {"1790", "1791", "1793", "1795", "1796", "1797"
	, "1799"};
	private static final string[] IPPFXS5 = {"12583", "12593", "12589", "12520", "10193", "11808"};

	private static final string[] IPPFXS6 = {"118321"};  /** * @param args */public static void main (string[] args) {//TODO auto-generated Method Stub//test data String
		Telnum = "+8618611503575";
		System.out.println ("Before trim telnum=" + telnum);
		Telnum = Trimtelnum (telnum);
		
		System.out.println ("Trimtelnum telnum=" + telnum);
		Telnum = "008618611503575";
		System.out.println ("Before trim telnum=" + telnum);
		Telnum = Trimtelnum (telnum);

		System.out.println ("Trimtelnum telnum=" + telnum);
		Telnum = "17951+8618211503458";
		System.out.println ("Before trim telnum=" + telnum);
		Telnum = Trimtelnum (telnum);
		
		System.out.println ("Trimtelnum telnum=" + telnum);
		Telnum = "1795818211503458"; System.ouT.println ("Before trim telnum=" + telnum);
		Telnum = Trimtelnum (telnum);
		
		System.out.println ("Trimtelnum telnum=" + telnum);
		Telnum = "1252015611503575";
		System.out.println ("Before trim telnum=" + telnum);
		Telnum = Trimtelnum (telnum);
		
		System.out.println ("Trimtelnum telnum=" + telnum);
		Telnum = "11832115611503575";
		System.out.println ("Before trim telnum=" + telnum);
		Telnum = Trimtelnum (telnum);
		
		System.out.println ("Trimtelnum telnum=" + telnum);
		Telnum = "118321+8615611503575";
		System.out.println ("Before trim telnum=" + telnum);
		Telnum = Trimtelnum (telnum);
	System.out.println ("Trimtelnum telnum=" + telnum);  /** * Eliminates the possible IP number, +86, 0086 prefix in the phone number * * @param telnum * @return/public static string Trimtelnum (string Telnum) {if (Telnum = = NULL | |
			"". Equals (Telnum)) {System.out.println ("Trimtelnum is null");
		return null;
		String ippfx6 = substring (telnum,0, 6);
		String ippfx5 = substring (telnum,0, 5); String ippfx4 = suBstring (telnum,0, 4); if (Telnum.length () > 7 && (SUBSTRING (telnum, 5, 1). Equals ("0") | | substring (telnum, 5, 1). Equals ("1" ) || SUBSTRING (Telnum, 5, 3). Equals ("400") | |
			SUBSTRING (Telnum, 5, 3). Equals ("+86")) && (InArray (ippfx5, IPPFXS5) | | InArray (IPPFX4, IPPFXS4))
		Telnum = substring (telnum, 5); else if (Telnum.length () > 8 && (substring (telnum, 6, 1). Equals ("0") | | substring (telnum, 6, 1). Equal S ("1") | | SUBSTRING (telnum, 6, 3). Equals ("400") | | SUBSTRING (telnum, 6, 3). Equals ("+86")) && InArray (ippfx6, IPPFXS6)) Telnum = substring (telnum, 6)
		;
		Remove IP Dial telnum = telnum.replace ("-", "");

		Telnum = Telnum.replace ("", "");
		if (substring (telnum, 0, 4). Equals ("0086")) Telnum = substring (telnum, 4);
		else if (substring (telnum, 0, 3). Equals ("+86")) Telnum = substring (telnum, 3); else if (substring (telnum, 0, 5). Equals ("00186")) Telnum = substring (telnum, 5);
	return telnum;
		/** * Intercept String * @param s * @param from * @return/protected static string substring (string s, int from) {
		try {return s.substring (from);
		catch (Exception e) {e.printstacktrace ();
	Return "";
		protected static string substring (string s, int from, int len) {try {return s.substring (from, from + len);
		catch (Exception e) {e.printstacktrace ();
	Return ""; /** * Determines whether a string is in an array of strings * @param target * @param arr * @return/protected static Boolean InArray (string
		Target, string[] arr {if (arr = null | | | arr.length = = 0) {return false;
		} if (target = = null) {return false;
			for (String S:arr) {if (Target.equals (s)) {return true;
	return false;
 }
}



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.