title: Restrict special characters & space programmatically
body: <p>I want to restrict user from entering special characters &amp; space programmatically.
  Below is my code</p>
  
  <pre><code>InputFilter[] alphaNumericFilter = new InputFilter[2];
          alphaNumericFilter[0] = new InputFilter() {
              @Override
              public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
                  for (int k = start; k &lt; end; k++) {
                      boolean isLetterOrDigit = Character.isLetterOrDigit(source.charAt(k));
                      boolean isSpaceChar = Character.isSpaceChar(source.charAt(k));
                      if ((source.length() &gt; 0 &amp;&amp; isSpaceChar) ||
                              (!isLetterOrDigit &amp;&amp; !isSpaceChar) ||
                              (isSpaceChar &amp;&amp; TextUtils.isEmpty(dest))) {
                          return "";
                      }
                  }
                  return null;
              }
          };
  </code></pre>
  
  <p>on pressing space it deleting last character.</p>