android正则表达式验证手机号与密码的封装

import android.content.Context;
import android.widget.Toast;

public class Aerifly {
    /**
     * 正则表达式:验证密码
     */
    public static final String REGEX_PASSWORD = "^[a-zA-Z0-9]{6,20}$";

    /**
     * 正则表达式:验证手机号
     */
    public static final String REGEX_TEL = "^((17[0-9])|(14[0-9])|(13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";

    //手机号验证
    public static boolean isMobile(Context content, String tel) {

        if (tel.matches(REGEX_TEL)) {

        } else {
            Toast.makeText(content, "手机号码格式不正确", Toast.LENGTH_SHORT).show();
            return false;
        }
        return true;
    }

    //密码验证
    public static boolean isPassword(Context content, String pwd) {
        if (pwd.matches(REGEX_PASSWORD)) {

        }else {
            Toast.makeText(content, "密码长度为6-20位不能包含特殊字符", Toast.LENGTH_SHORT).show();
            return false;
        }
        return true;

    }
}

猜你喜欢

转载自blog.csdn.net/qq_42081816/article/details/80522809