亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

java正則表達(dá)式表單驗(yàn)證類工具類(驗(yàn)證郵箱、手機(jī)號(hào)碼、qq號(hào)碼等)

 更新時(shí)間:2014年04月27日 09:13:48   作者:  
這篇文章主要介紹了java使用正則表達(dá)式進(jìn)行表單驗(yàn)證工具類,可以驗(yàn)證郵箱、手機(jī)號(hào)碼、qq號(hào)碼等方法,需要的朋友可以參考下

java使用正則表達(dá)式進(jìn)行表單驗(yàn)證工具類,可以驗(yàn)證郵箱、手機(jī)號(hào)碼、qq號(hào)碼等

復(fù)制代碼 代碼如下:

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);
    }
}

相關(guān)文章

最新評(píng)論