Package com.yaowen.mytest;
Import java.io.IOException;
Import Java.util.regex.Matcher;
Import Java.util.regex.Pattern;
public class Check {
Judgment call
public static Boolean Istelephone (String phonenumber) {
String phone = "0\\d{2,3}-\\d{7,8}";
Pattern p = pattern.compile (phone);
Matcher m = P.matcher (PhoneNumber);
return m.matches ();
}
Determine the phone number
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);
return m.matches ();
}
Determine mailbox
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);
return m.matches ();
}
Determine date format: YYYY-MM-DD
public static Boolean isvaliddate (String sdate) {
String datePattern1 = "\\d{4}-\\d{2}-\\d{2}";
String datePattern2 = "^ ((\\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]))))) ";
if ((sdate! = null)) {
Pattern pattern = pattern.compile (DATEPATTERN1);
Matcher match = Pattern.matcher (sdate);
if (Match.matches ()) {
Pattern = Pattern.compile (datePattern2);
Match = Pattern.matcher (sdate);
return match.matches ();
} else {
return false;
}
}
return false;
}
Verify Amount
public static Boolean isnumber (String str)
{
Java.util.regex.Pattern Pattern=java.util.regex.pattern.compile ("^ ([1-9]{1}\\d*) | ( [0] {1})) (\\. (\\d) {0,2})? $"); A regular expression that determines the number of digits after a decimal point
Java.util.regex.Matcher Match=pattern.matcher (str);
if (Match.matches () ==false)
{
return false;
}
Else
{
return true;
}
}
}
This article is from the "9151568" blog, please be sure to keep this source http://9161568.blog.51cto.com/9151568/1685258
Regular Expression Judgment tool code (phone, phone, Email, date wait) commonly used under Android