79903

Android EditText : How to avoid user enter smileys?

Question:

I would like to avoid to the user to put a smiley with the keyboard into an EditText. Is it possible ?

<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/abL44.jpg" data-original="https://i.stack.imgur.com/abL44.jpg" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

Answer1:

You can define your input type and only accept letters or change your keyboard type:

<blockquote> <blockquote>

<a href="https://developer.android.com/training/keyboard-input/style.html" rel="nofollow">https://developer.android.com/training/keyboard-input/style.html</a>

</blockquote> </blockquote>

Or you can only accept some specific digits:

<blockquote> <blockquote>

<a href="https://stackoverflow.com/questions/2361497/how-to-create-edittext-accepts-alphabets-only-in-android" rel="nofollow">How to create EditText accepts Alphabets only in android?</a>

</blockquote> </blockquote>

Answer2:

Editing answer from <a href="https://stackoverflow.com/a/9030749/3119752" rel="nofollow">here</a>.

This will allow only ASCII characters to be entered in EditText.

edittext.setFilters(new InputFilter[] { new InputFilter() { public CharSequence filter(CharSequence src, int start, int end, Spanned dst, int dstart, int dend) { if(src.equals("")){ // for backspace return src; } if(src.toString().matches("[\\x00-\\x7F]+")){ return src; } return ""; } } });

Recommend

  • Unicode lowercase characters?
  • What is the intersection of two languages with different alphabets? [closed]
  • how to allow only spaces and alpha in name fields php using regex
  • Pandas: Randomize letters in a column
  • What is the learning curve for development on JD Edwards?
  • Different outcomes when using tf.Variable() and tf.get_variable()
  • Multi-dimensional regression with Keras
  • SCSS Language Injection in Pycharm
  • JSF Cannot format given Object as a Date
  • Exposing an enum in a QML signal
  • Rx produce and consume on different threads
  • How to change default stop edit behavior in jtable
  • Autohotkey script running program with command line arguments
  • goJS dropdown remove items
  • Passing variable arguments using PowerShell's Start-Process cmdlet
  • Jenkins: FATAL: Could not initialize class hudson.util.ProcessTree$UnixReflection
  • Xcode 4 NSLog Macro link in Xcode 3
  • How do I alternate colors in Flat List (React Native)
  • Listbox within Listbox and scrolling trouble in Windows Phone 7 Silverlight
  • Disable Enter in editText android
  • Cannot resolve symbol 'MyApi'
  • Asynchronous UI Testing in Xcode With Swift
  • If I include Java 8 in my Android app does that affect which devices it will work on?
  • Why is an OPTIONS request sent to the server?
  • What is Eclipse's Declaration View used for?
  • RectangularRangeIndicator format like triangular using dojo
  • Cross-Platform Protobuf Serialization
  • Release, debug version and Authorization Google?
  • jquery mobile loadPage not working
  • Unanticipated behavior
  • Matrix multiplication with MKL
  • How to get icons for entities from eclipse?
  • Revoking OAuth Access Token Results in 404 Not Found
  • Proper way to use connect-multiparty with express.js?
  • Load html files in TinyMce
  • CSS Applying specific rule for a specific monitor resolution with only CSS is posible?
  • What are the advantages and disadvantages of reading an entire file into a single String as opposed
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • JaxB to read class hierarchy
  • Converting MP3 duration time