您好,登錄后才能下訂單哦!
package com.yaowen.mytest;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Check {
// 判斷電話
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();
}
// 判斷手機(jī)號(hào)
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();
}
// 判斷郵箱
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();
}
// 判斷日期格式: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;
}
//驗(yàn)證金額
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})?$"); // 判斷小數(shù)點(diǎn)后一位的數(shù)字的正則表達(dá)式
java.util.regex.Matcher match=pattern.matcher(str);
if(match.matches()==false)
{
return false;
}
else
{
return true;
}
}
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。