当前位置:网站首页>Regular verification of mobile phone number and email [easy to understand]

Regular verification of mobile phone number and email [easy to understand]

2022-06-28 09:24:00 Java architects must see

Hello everyone , I'm wang Jun , An architect who can write code and recite poetry . Today, let's talk about the mobile phone number 、 Mailbox regular validation [ Easy to understand ], I hope it can help you make progress !!!

private static String MOBILE_REGEX = "^(13[0-9]|15[012356789]|17[3678]|18[0-9]|14[57])[0-9]{8}$";

private static String EMAIL_REGEX = "^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$";


/**  *  Regular verification of mobile phone number   * @param str  * @return  */ public static boolean validateMobile(String str) {
    Pattern pa = Pattern.compile(MOBILE_REGEX);
    Matcher ma = pa.matcher(str);
    while (ma.find()) {
        return true;
    }
    return false;
}

/**  *  Mailbox regular validation   * @param str  * @return  */ public static boolean validateEmail(String str) {
    Pattern pa = Pattern.compile(EMAIL_REGEX);
    Matcher ma = pa.matcher(str);
    while (ma.find()) {
        return true;
    }
    return false;
}
原网站

版权声明
本文为[Java architects must see]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/179/202206280920441446.html