Email and phone Number Validation in android

后端 未结 12 1257
青春惊慌失措
青春惊慌失措 2020-12-02 11:03

I have a registration form in my application which I am trying to validate. I\'m facing some problems with my validation while validating the phone number and email fields.<

12条回答
  •  既然无缘
    2020-12-02 11:55

    try this:

    extMobileNo.addTextChangedListener(new MyTextWatcher(extMobileNo));
    
    private boolean validateMobile()    {   
    
        String mobile =extMobileNo.getText().toString().trim();
        if(mobile.isEmpty()||!isValidMobile(mobile)||extMobileNo.getText().toString().toString().length()<10 || mobile.length()>13 )
    
        {
                inputLayoutMobile.setError(getString(R.string.err_msg_mobile));
            requestFocus(extMobileNo);
            return false;
        }
    
        else {
            inputLayoutMobile.setErrorEnabled(false);
        }
    
        return true;
    }
    
    private static boolean isValidMobile(String mobile)
    {
        return !TextUtils.isEmpty(mobile)&& Patterns.PHONE.matcher(mobile).matches();
    }
    

提交回复
热议问题