校验手机号和获取验证码

来源:互联网 发布:淘宝客关闭返利 编辑:程序博客网 时间:2024/05/16 04:52
public class CheckTelUseful {private Context context;public CheckTelUseful(Context context) {    this.context = context;}/** * 校验手机号 * * @author zjf * @time 2017/4/13 9:19 */public boolean checkTelIsUseful(String tel) {    String num = "[1][3578]\\d{9}";                      //"[1]"代表第1位为数字1,"[3578]"代表第二位可以为3、5、7、8中的一个,"\\d{9}"代表后面是可以是0~9的数字,有9位。    if (TextUtils.isEmpty(tel)) {        return false;    } else {        //matches():字符串是否在给定的正则表达式匹配        return tel.matches(num);    }}/** * 获取验证码 * * @author zjf * @time 2017/4/13 9:15 */public String getVerification(EditText editText_tel) {    if (editText_tel.getText() != null && !TextUtils.isEmpty(editText_tel.getText().toString())) {        if (checkTelIsUseful(editText_tel.getText().toString())) {//手机号合法,获取验证码            return "";        } else {            new ToastHelper().showToast(context, "手机号不合法");            return "";        }    } else {        new ToastHelper().showToast(context, "手机号不能为空");        return "";    }}

}

1 0