Android: are there any good solutions how to validate Editboxes

前端 未结 4 1548
感动是毒
感动是毒 2021-01-07 04:01

For example, I want to Validate Minimum-Length, and if it\'s Email, a PhoneNumber.

How is this possible in android. I wan

4条回答
  •  攒了一身酷
    2021-01-07 04:33

    For the validation of Text box

    1. minimum length: u can directly give the length of that text. 2. mail validation:

    public boolean isEmailValid(String email)
            {
                 String regExpn =
                     "^(([\\w-]+\\.)+[\\w-]+|([a-zA-Z]{1}|[\\w-]{2,}))@"
                         +"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?"
                           +"[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\."
                           +"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?"
                           +"[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
                           +"([a-zA-Z]+[\\w-]+\\.)+[a-zA-Z]{2,4})$";
    
             CharSequence inputStr = email;
    
             pattern = Pattern.compile(regExpn,Pattern.CASE_INSENSITIVE);
             matcher = pattern.matcher(inputStr);
    
             if(matcher.matches())
                return true;
             else
                return false;
     }
    

    1. For phone number: If you want to fix length then give the length and the input type is number.

提交回复
热议问题