正则表达式判断是否是手机号,或电话号码

来源:互联网 发布:excel 数据分析按钮 编辑:程序博客网 时间:2024/06/09 14:00
    /**     * 判断传入的字符串是否是一个手机号码     *     * @param strPhone     * @return     */    public static boolean isPhoneNumber(String strPhone) {        String str = "^((13[0-9])|(15[^4,\\D])|(18[0-9])|(17[0-9])|(14[0-9]))\\d{8}$";        Pattern p = Pattern.compile(str);        Matcher m = p.matcher(strPhone);        return m.find();    }    /**     * 判断传入的字符串是否是一个电话号码或手机号码     *     * @param strPhone     * @return     */    public static boolean isLandlineNumber(String strPhone) {        String str = "^0\\d{2,3}-?\\d{7,8}$|^(13[0-9]|15[0-9]|18[0-9]|14[0-9]|17[0-9])\\d{8}$";        Pattern p = Pattern.compile(str);        Matcher m = p.matcher(strPhone);        return m.find();    }
原创粉丝点击