Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android : Minimum Length of password in edittext

Tags:

android

In android is there any simple way of setting minimum password length in edittext? In xml there is only an option of max length but not minimum.

Options like setting ems and width fits for restricting the length but what about when to set minimum length???

I found this in the documentation:

DevicePolicyManager mDPM;
ComponentName mDeviceAdminSample;
int pwLength;
...
mDPM.setPasswordMinimumLength(mDeviceAdminSample, pwLength);

But is there any simpler method other than this?

like image 547
Sam Avatar asked Mar 15 '11 06:03

Sam


1 Answers

You can do some validation on the edittext when the user clicks submit.

public void onSubmitClicked(View v) 
{ 
    String pass = passwordEditText.getText().toString(); 
    if(TextUtils.isEmpty(pass) || pass.length() < [YOUR MIN LENGTH]) 
    { 
        passwordEditText.setError("You must have x characters in your password"); 
        return; 
    }

    //continue processing

}
like image 183
runor49 Avatar answered Nov 02 '22 12:11

runor49