java正則表達(dá)式表單驗(yàn)證類工具類(驗(yàn)證郵箱、手機(jī)號(hào)碼、qq號(hào)碼等)
java使用正則表達(dá)式進(jìn)行表單驗(yàn)證工具類,可以驗(yàn)證郵箱、手機(jī)號(hào)碼、qq號(hào)碼等
package util;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 使用正則表達(dá)式進(jìn)行表單驗(yàn)證
*
*/
public class RegexValidateUtil {
static boolean flag = false;
static String regex = "";
public static boolean check(String str, String regex) {
try {
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(str);
flag = matcher.matches();
} catch (Exception e) {
flag = false;
}
return flag;
}
/**
* 驗(yàn)證非空
*
* @param email
* @return
*/
public static boolean checkNotEmputy(String notEmputy) {
regex = "^\\s*$";
return check(notEmputy, regex) ? false : true;
}
/**
* 驗(yàn)證郵箱
*
* @param email
* @return
*/
public static boolean checkEmail(String email) {
String regex = "^\\w+[-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$ ";
return check(email, regex);
}
/**
* 驗(yàn)證手機(jī)號(hào)碼
*
* 移動(dòng)號(hào)碼段:139、138、137、136、135、134、150、151、152、157、158、159、182、183、187、188、147
* 聯(lián)通號(hào)碼段:130、131、132、136、185、186、145
* 電信號(hào)碼段:133、153、180、189
*
* @param cellphone
* @return
*/
public static boolean checkCellphone(String cellphone) {
String regex = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8}$";
return check(cellphone, regex);
}
/**
* 驗(yàn)證固話號(hào)碼
*
* @param telephone
* @return
*/
public static boolean checkTelephone(String telephone) {
String regex = "^(0\\d{2}-\\d{8}(-\\d{1,4})?)|(0\\d{3}-\\d{7,8}(-\\d{1,4})?)$";
return check(telephone, regex);
}
/**
* 驗(yàn)證傳真號(hào)碼
*
* @param fax
* @return
*/
public static boolean checkFax(String fax) {
String regex = "^(0\\d{2}-\\d{8}(-\\d{1,4})?)|(0\\d{3}-\\d{7,8}(-\\d{1,4})?)$";
return check(fax, regex);
}
/**
* 驗(yàn)證QQ號(hào)碼
*
* @param QQ
* @return
*/
public static boolean checkQQ(String QQ) {
String regex = "^[1-9][0-9]{4,} $";
return check(QQ, regex);
}
}
- Java使用正則表達(dá)式驗(yàn)證用戶名和密碼的方法
- Java常用正則表達(dá)式驗(yàn)證類完整實(shí)例【郵箱、URL、IP、電話、身份證等】
- Java使用正則表達(dá)式驗(yàn)證手機(jī)號(hào)和電話號(hào)碼的方法
- Java正則表達(dá)式驗(yàn)證固定電話號(hào)碼符合性
- Java常用正則表達(dá)式驗(yàn)證工具類RegexUtils.java
- Java使用正則表達(dá)式對(duì)注冊頁面進(jìn)行驗(yàn)證功能實(shí)現(xiàn)
- java正則表達(dá)式驗(yàn)證郵箱、電話號(hào)碼示例
- Java正則表達(dá)式驗(yàn)證是否包含某個(gè)字符串的示例代碼
相關(guān)文章
Java長度不足左位補(bǔ)0的3種實(shí)現(xiàn)方法
這篇文章主要介紹了Java長度不足左位補(bǔ)0的3種實(shí)現(xiàn)方法小結(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12基于java TCP網(wǎng)絡(luò)通信的實(shí)例詳解
本篇文章是對(duì)java中TCP網(wǎng)絡(luò)通信的實(shí)例進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05SpringBoot Session共享實(shí)現(xiàn)圖解
這篇文章主要介紹了SpringBoot Session共享實(shí)現(xiàn)圖解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-01-01Java多線程Queue、BlockingQueue和使用BlockingQueue實(shí)現(xiàn)生產(chǎn)消費(fèi)者模型方法解析
這篇文章主要介紹了Java多線程Queue、BlockingQueue和使用BlockingQueue實(shí)現(xiàn)生產(chǎn)消費(fèi)者模型方法解析,涉及queue,BlockingQueue等有關(guān)內(nèi)容,具有一定參考價(jià)值,需要的朋友可以參考。2017-11-11idea無法打斷點(diǎn),單擊或雙擊代碼行左側(cè)區(qū)域無效的解決
這篇文章主要介紹了idea無法打斷點(diǎn),單擊或雙擊代碼行左側(cè)區(qū)域無效的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-09-09Spring Boot使用Spring的異步線程池的實(shí)現(xiàn)
這篇文章主要介紹了Spring Boot使用Spring的異步線程池的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-02-02