Android:验证EditText输入框输入的手机号

    //验证手机号
    private boolean judPhone() {
        if (TextUtils.isEmpty(edit_phone.getText().toString().trim())) {
            Toast.makeText(AddAccountActivity.this, "请输入您的电话号码", Toast.LENGTH_LONG).show();
            edit_phone.requestFocus();
            return false;
        } else if (edit_phone.getText().toString().trim().length() != 11) {
            Toast.makeText(AddAccountActivity.this, "您的电话号码位数不正确", Toast.LENGTH_LONG).show();
            edit_phone.requestFocus();
            return false;
        } else {
            String phone_number = edit_phone.getText().toString().trim();
            String num = "[1][358]\\d{9}";
            if (phone_number.matches(num))
                return true;
            else {
                Toast.makeText(AddAccountActivity.this, "请输入正确的手机号码", Toast.LENGTH_LONG).show();
                return false;
            }
        }
    }

你可能感兴趣的:(Android)