Personal Information Verification

Source: Internet
Author: User

Demo Example:

Package it.com.cc;

Import Java.util.regex.Matcher;

Import Java.util.regex.Pattern;

Import android.app.Activity;

Import Android.os.Bundle;

public class Demo4activity extends Activity {

@Override

public void OnCreate (Bundle savedinstancestate) {

Super.oncreate (savedinstancestate);

Setcontentview (R.layout.main);

Boolean isphone = Ismobileno ("1684565463453");

Boolean isemail = Isemail ("[email protected]");

Boolean isnumber = IsNumeric ("564465");

System.out.println ("isnumeric=" + isnumber + "isphone=" + isphone

+ "isemail=" + isemail + "qq===========");

}

Determine if the phone format is correct

public boolean Ismobileno (String mobiles) {

Pattern P = Pattern

. Compile ("^ (13[0-9]) | ( 15[^4,\\D]) | (18[0,5-9])) \\d{8}$ ");

Matcher m = p.matcher (mobiles);

return m.matches ();

}

Determine if the email format is correct

public boolean isemail (String email) {

String str = "^ ([a-za-z0-9_\\-\\.] +) @ ((\\[[0-9]{1,3}\\. [0-9] {1,3}\\. [0-9] {1,3}\\.) | ([a-za-z0-9\\-]+\\.) +)) ([a-za-z]{2,4}| [0-9] {1,3}) (\\]?) $";

Pattern p = pattern.compile (str);

Matcher m = p.matcher (email);

return m.matches ();

}

Judging whether it's all numbers

public boolean isnumeric (String str) {

Pattern pattern = Pattern.compile ("[0-9]*");

Matcher isnum = Pattern.matcher (str);

if (!isnum.matches ()) {

return false;

}

return true;

}

}

To determine the logical processing of feedback information:

Userinfostr = Userinfo.gettext (). toString (). Trim ();

Contentstr = Content.gettext (). toString (). Trim ();

if (! Utils.checknetworkavalible ()) {

Toast.maketext (View.getcontext (), "Network is not available, check your network settings!" ",

Toast.length_short). Show ();

Return

}

if (contentstr! = NULL && CONTENTSTR! = ""

&& contentstr.length () > 0) {

if (!isnumeric (USERINFOSTR) &&!isemail (USERINFOSTR)) {

Alerdialog ("Phone or mailbox format is incorrect");

Return

}

if (IsNumeric (USERINFOSTR) &&!ismobileno (USERINFOSTR)) {

Alerdialog ("Phone or mailbox format is incorrect");

Return

}

Threadpoolwrap.getthreadpool (). ExecuteTask (runnable);

Toast.maketext (View.getcontext (), "submit success, thanks for support!" ",

Toast.length_short). Show ();

Userinfo.settext ("");

Content.settext ("");

} else {

Toast.maketext (View.getcontext (), "Please input feedback content",

Toast.length_short). Show ();

}

}

Reference:

Http://blog.sina.com.cn/s/blog_4b2fd9350100oa43.html

1.java Authentication IP Address:

Pattern pattern = Pattern.compile ("\\b (?! \\d\\d\\d) \\d+|1\\d\\d|2[0-4]\\d|25[0-5] \ \. ((?! \\d\\d\\d) \\d+|1\\d\\d|2[0-4]\\d|25[0-5] \ \. ((?! \\d\\d\\d) \\d+|1\\d\\d|2[0-4]\\d|25[0-5] \ \. ((?! \\d\\d\\d) (\\d+|1\\d\\d|2[0-4]\\d|25[0-5]) \\b ");

Matcher Matcher = Pattern.matcher ("127.400.600.2"); To verify 127.400.600.2 as an example

System.out.println (Matcher.matches ());

2. Java validation Date time, resolve run month:

Pattern pattern = Pattern.compile ("^ (\\d{2} (([02468][048]) | ( [13579] [26])) [\\-\\/\\s]? (((0? [13578]) | (1[02])) [\\-\\/\\s]? ((0? [1-9]) | ([1-2][0-9]) | (3[01])) | ((0? [469]) | (11)) [\\-\\/\\s]? ((0? [1-9]) | ([1-2][0-9]) | (30))) | (0?2[\\-\\/\\s]? ((0? [1-9]) | ([1-2][0-9])))) | (\\d{2} ([02468][1235679]) | ( [13579] [01345789])) [\\-\\/\\s]? (((0? [13578]) | (1[02])) [\\-\\/\\s]? ((0? [1-9]) | ([1-2][0-9]) | (3[01])) | ((0? [469]) | (11)) [\\-\\/\\s]? ((0? [1-9]) | ([1-2][0-9]) | (30))) | (0?2[\\-\\/\\s]? ((0? [1-9]) | (1[0-9]) | (2[0-8]))))) (\\s ((0?[ 0-9]) | ([1-2][0-3])) \ \:([0-5]? [0-9]) ((\\s) | (\ \:([0-5]? [0-9])))? $");

Matcher Matcher = Pattern.matcher ("2000-02-29 23:59:59");

System.out.println (Matcher.matches ());

3.java Verify Mailbox Format:

Pattern pattern = pattern.compile ("^ [a-za-z0-9_\\-\\.] +) @ ((\\[[0-9]{1,3}\\. [0-9] {1,3}\\. [0-9] {1,3}\\.) | ([a-za-z0-9\\-]+\\.) +)) ([a-za-z]{2,4}| [0-9] {1,3}) (\\]?) $");

Matcher Matcher = Pattern.matcher ("[email protected]");

System.out.println (Matcher.matches ());

According to the actual development on September 7, 2009 the latest statistics:
China Telecom launches Chinese 3G number segment: China Unicom 185,186, Chinese mobile 188,187, China Telecom 189,180 total 6 segments.
3G Business-specific section 180-189 has been basically allocated to the operators, of which 180, 189 allocated to China Telecom, 187, 188 is China Mobile use, 185, 186 belong to the new Unicom.
China Mobile has number segments: 139, 138, 137, 136, 135, 134, 159, 158, 157 (3G), 152, 151, 150, 188 (3G), 187 (3G), 14 segment
China Unicom has number segments: 130, 131, 132, 155, 156 (3G), 186 (3G), 185 (3G), 6 segment
China Telecom has a number segment: 133, 153, 189 (3G), (3G), 4 number segment
Move:
Segment 2G (GSM network) has 139,138,137,136,135,134 (0-8), 159,158,152,151,150
Segment 3G (TD-SCDMA Network) has 157,188,187
147 is the mobile TD network card special number segment.
Unicom:
Segment 2G (GSM network) has 130,131,132,155,156
Segment 3G (WCDMA network) has 186,185
Telecom:
2G segment (CDMA network) has 133,153
3G segment (CDMA network) has 189,180


Class for verifying mobile phone numbers and mailboxes

Package com.ccit.networld.ccs.common.util;

Import java.io.IOException;
Import Java.util.regex.Matcher;
Import Java.util.regex.Pattern;

Import Org.apache.log4j.Logger;

public class Classpathresource {
private static final Logger Logger = Logger.getlogger (Classpathresource.class);
public static Boolean Ismobileno (String mobiles) {
Pattern p = pattern.compile ("^ (13[0-9]) | ( 15[^4,\\D]) | (18[0,5-9])) \\d{8}$ ");
Matcher m = p.matcher (mobiles);
Logger.info (m.matches () + "---");
return m.matches ();
}

public static Boolean isemail (String email) {
String str= "^ ([a-za-z0-9]*[-_]?[ a-za-z0-9]+) *@ ([a-za-z0-9]*[-_]?[ a-za-z0-9]+) +[\\.] [A-za-z] {2,3} ([\\.] [A-za-z] {2})? $";
Pattern p = pattern.compile (str);
Matcher m = p.matcher (email);
Logger.info (m.matches () + "---");
return m.matches ();
}
public static void Main (string[] args) throws IOException {
System.out.println (Classpathresource.isemail ("[email protected]"));
}
}

Personal Information Verification

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.