Java正则校验手机号

package com.app.main.utils;

import java.util.regex.Pattern;

/**
 * Created with IDEA
 * author:Dingsheng Huang
 * Date:2019/7/2
 * Time:下午6:51
 */
public class RegexUtils {

    /**
     *  正则:手机号(简单), 1字头+10位数字即可.
     * @param in
     * @return
     */
    public static boolean validateMobilePhone(String in) {
        Pattern pattern = Pattern.compile("^[1]\\d{10}$");
        return pattern.matcher(in).matches();
    }

    public static void main(String[] args) {
        System.out.println(validateMobilePhone("17778014396"));

        System.out.println(validateMobilePhone("123"));
    }
}

Java正则校验手机号_第1张图片

你可能感兴趣的:(Java)