Java校验手机号格式

package com.shucha.digitalportalbackstage.biz.utils;

import org.springframework.stereotype.Component;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author tqf
 * @Description 手机号格式校验
 * @Version 1.0
 * @since 2022-03-15 15:28
 */
@Component
public class RegexPhoneUtil {
    private static String REGEX_PHONE = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17[013678])|(18[0,5-9]))\\d{8}$";

    /**
     * 校验手机号格式是否正确
     * @param phone
     * @return
     */
     public Boolean regexPhone(String phone){
        Boolean b;
        if(phone.length() != 11){
            b = false;
        }else{
            Pattern p = Pattern.compile(REGEX_PHONE);
            Matcher m = p.matcher(phone);
            boolean isMatch = m.matches();
            if(isMatch){
                b = true;
            } else {
                b = false;
            }
        }
        return b;
    }

}

posted @ 2022-08-04 19:12  码奴生来只知道前进~  阅读(19)  评论(0)    收藏  举报