android - Failed to Restrict Special Characters in EditText with inputType = typePassword -
i have login form in android application, problem when entered special characters bypass checks. meant log in thru invalid password , redirect next activity. had used android:digits property of edittext. works fine on simple edittext not working when set inputtype property.
xml:
<edittext android:layout_weight="2" android:id="@+id/edt_signup_password" android:layout_width="match_parent" android:inputtype="textpassword" android:digits="0,1,2,3,4,5,6,7,8,9,qwertzuiopasdfghjklyxcvbnm" android:background="@drawable/edittext" android:padding="4dp" android:maxlength="15" android:layout_height="wrap_content" android:ems="10" /> how can restrict special characters when android:inputtype="textpassword" . in advance
one way via java utilize regex.
you define characters want allow such:
final static string input = "[ a-za-z0-9_-]+"; final static pattern pattern = pattern.compile(input); this input pattern allow space, underscore, dash, 0-9 , lower , upper case letters.
then check inputted text against pattern utilize following:
matcher matcher = pattern.matcher(textview.gettext().tostring()); if (matcher.matches()) { //login here } else { //do else } android xml android-layout
No comments:
Post a Comment