开发者

Android : Minimum Length of password in edittext

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;
ComponentN开发者_JAVA技巧ame mDeviceAdminSample;
int pwLength;
...
mDPM.setPasswordMinimumLength(mDeviceAdminSample, pwLength);

But is there any simpler method other than this?


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

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜