title: EditText validation with TextWatcher
body: <p>I have a Dialog with a <code>EditText</code> and a button. This <code>EditText</code> will name the database table I will create so its of the utmost importance it is validated. So i would like to pose 2 questions:</p>
  
  <p>1) This is quite simple, but i couldn't fin it anywhere: what characters can a database table name accept? Can it accept numbers? And can a number be the first character?</p>
  
  <p>2) I've managed to validate the <code>EditText</code> using <code>TextWtacher</code>. Here's the code:</p>
  
  <pre><code>et_name.addTextChangedListener(new TextWatcher() {
  
  public void afterTextChanged(Editable s) {
  
      String filtered_str = s.toString();
  
          if (filtered_str.matches(".*[^a-z^0-9].*")) {
  
          filtered_str = filtered_str.replaceAll("[^a-z^0-9]", "");
  
          s.clear();
  
          // s.insert(0, filtered_str);
  
          Toast.makeText(context,
              "Only lowercase letters and numbers are allowed!",
              Toast.LENGTH_SHORT).show();
  
      }
  
  }
  
      public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
  
      public void onTextChanged(CharSequence s, int start, int before, int count) {}
  });
  </code></pre>
  
  <p>Currently, if the user inserts any character other than lowercase letters and numbers, the textbox is cleared. 
  If I uncomment <code>s.insert(0, filtered_str);</code> in order to to replace the EditText with the filtered string, my app hangs. And guess what I find in the debug?</p>
  
  <p>ERROR/AndroidRuntime(2454): <code>java.lang.StackOverflowError</code>  =D</p>
  
  <p>The question is... how can I replace the s text?</p>
  
  <p>-> <code>s.replace(0, s.toString().length(), filtered_str);</code> (remove s.clear, of course) doesn't seem to work either.</p>