正則表達式語法 2

經過分析別人的表達式能夠加深理解。正則表達式

收集一些經常使用的正則表達式:spa

   /**
     * 正則表達式:驗證用戶名
     */
    public static final String REGEX_USERNAME = "^[a-zA-Z]\\w{5,17}$";
 
    /**
     * 正則表達式:驗證密碼
     */
    public static final String REGEX_PASSWORD = "^[a-zA-Z0-9]{6,16}$";
 
    /**
     * 正則表達式:驗證手機號
     */
    public static final String REGEX_MOBILE = "^1[3,5,8]([0-9]{9})$";
    /**
     * 正則表達式:驗證郵箱
     */
    public static final String REGEX_EMAIL = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
 
    /**
     * 正則表達式:驗證漢字
     */
    public static final String REGEX_CHINESE = "^[\u4e00-\u9fa5],{0,}$";
 
    /**
     * 正則表達式:驗證身份證
     */
    public static final String REGEX_ID_CARD = "(^\\d{18}$)|(^\\d{15}$)";
 
    /**
     * 正則表達式:驗證URL
     */
    public static final String REGEX_URL = "http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?";
 
    /**
     * 正則表達式:驗證IP地址
     */
    public static final String REGEX_IP_ADDR = "(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)";

其中驗證手機號不要吐槽,本身寫的,下降了要求,由於運營商肯能增長號段。
最新的還遇到17x,14x號段,能夠再加進去。code

相關文章
相關標籤/搜索