Skip to content

Instantly share code, notes, and snippets.

@seemike
Last active March 16, 2022 18:37
Show Gist options
  • Save seemike/6388429 to your computer and use it in GitHub Desktop.
Save seemike/6388429 to your computer and use it in GitHub Desktop.
Android: restrict EditText field input to alphanumeric characters
<EditText
android:inputType="textNoSuggestions"
android:digits="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"
/>
@Rioland
Copy link

Rioland commented Jun 6, 2019

Try this
String correct= text.getText().to String ()
String formatingValue=correct.replaceAll("[a-zA-Z0-9]","");

This how it works it will get all special characters and replace them with empty string.

@ParryPatel021
Copy link

ParryPatel021 commented Jul 12, 2019

This is working for me. Thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment