EditText in Google Android


I want to create the <strong>EditText</strong> which allow <strong>Numeric Values</strong>, <strong>Comma</strong> and <strong>Delete</strong> and other values are ignore.

So How I can achieve this by programming code ?



I achieved same thing using follwing code, hope you will also find help from it.

editText.addTextChangedListener(controller); @Override public void afterTextChanged(Editable s) { if(s.trim.length() > 0) { int start = s.toString().length() - 1; int a = (int) s.charAt(start); if (!(a >= 48 && a <= 57 || a == 44)) s = s.delete(start, start + 1); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { }


To restrict what characters can be typed into an android EditText, you must set them in the android:digits XML attribute. See <a href="http://developer.android.com/reference/android/widget/TextView.html#attr_android:digits" rel="nofollow">http://developer.android.com/reference/android/widget/TextView.html#attr_android:digits</a> . Make sure to also validate user input before putting it into storage.


just simple ,

you want to create a text-field like that you can enter the new string must have some grammar that you want to allow.

i have some email validation grammar that can help you.

string = "/alphabetics/number/special-character" ;

and another is

user-entered-string = " ";

just compare user-entered-string's lexems and you defined grammar.


  • EditText in Google Android
  • Android AutoComplete TextBox, setting your own specific suggestions?
  • Styling item Views in Android ListView
  • National letter selector doesn't appear
  • ArrayAdapter need to be clear even i am creating a new one
  • Enter character immediately after entering first character in android
  • Textwatcher doesn't recognize space
  • how to handle with addTextChangedListener and memory
  • How to hide or deactivate a TextField and a Label with javafx
  • JQgrid : Change entire row's font color if one column is filled
  • C# “cannot assign field because it is a foreach iteration variable”
  • how to set id for each item in ListView
  • Excel 2007: Format of email address from Outlook 2007
  • Updating and removing unique join relationships in CakePHP
  • Negating Regex PO BOX
  • How do you remove the JComboBox 'click and see dropdown' functionality?
  • Is there a way to disable a specific event in kendo ui scheduler?
  • Galaxy S4 Android Custom Camera Issue
  • Android Activity.onWindowFocusChanged doesn't get called from within TabHost
  • Rearranging Cells in UITableView Bug & Saving Changes
  • retrieve vertices with no linked edge in arangodb
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • python regex in pyparsing
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Exception on Android 4.0 `android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)`
  • Change div Background jquery
  • Android Google Maps API OnLocationChanged only called once
  • apache spark aggregate function using min value
  • unknown Exception android
  • EntityFramework adding new object to nested object collection
  • Checking variable from a different class in C#
  • Sorting a 2D array using the second column C++
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • failed to connect to specific WiFi in android programmatically
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal
  • How can I use threading to 'tick' a timer to be accessed by other threads?