Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/text/InputFilter#nestedclasses) \| [Methods](https://developer.android.com/reference/android/text/InputFilter#pubmethods)

# InputFilter

*** ** * ** ***

` public interface InputFilter `   
` `

|---|
| android.text.InputFilter |

Known indirect subclasses [DateKeyListener](https://developer.android.com/reference/android/text/method/DateKeyListener), [DateTimeKeyListener](https://developer.android.com/reference/android/text/method/DateTimeKeyListener), [DialerKeyListener](https://developer.android.com/reference/android/text/method/DialerKeyListener), [DigitsKeyListener](https://developer.android.com/reference/android/text/method/DigitsKeyListener), [InputFilter.AllCaps](https://developer.android.com/reference/android/text/InputFilter.AllCaps), [InputFilter.LengthFilter](https://developer.android.com/reference/android/text/InputFilter.LengthFilter), [LoginFilter](https://developer.android.com/reference/android/text/LoginFilter), [LoginFilter.PasswordFilterGMail](https://developer.android.com/reference/android/text/LoginFilter.PasswordFilterGMail), [LoginFilter.UsernameFilterGMail](https://developer.android.com/reference/android/text/LoginFilter.UsernameFilterGMail), [LoginFilter.UsernameFilterGeneric](https://developer.android.com/reference/android/text/LoginFilter.UsernameFilterGeneric), [NumberKeyListener](https://developer.android.com/reference/android/text/method/NumberKeyListener), [TimeKeyListener](https://developer.android.com/reference/android/text/method/TimeKeyListener) [DateKeyListener](https://developer.android.com/reference/android/text/method/DateKeyListener) For entering dates in a text field. [DateTimeKeyListener](https://developer.android.com/reference/android/text/method/DateTimeKeyListener) For entering dates and times in the same text field. [DialerKeyListener](https://developer.android.com/reference/android/text/method/DialerKeyListener) For dialing-only text entry

<br />

As for all implementations of `https://developer.android.com/reference/android/text/method/KeyListener`, this class is only concerned with hardware keyboards. [DigitsKeyListener](https://developer.android.com/reference/android/text/method/DigitsKeyListener) For digits-only text entry

<br />

As for all implementations of `https://developer.android.com/reference/android/text/method/KeyListener`, this class is only concerned with hardware keyboards. [InputFilter.AllCaps](https://developer.android.com/reference/android/text/InputFilter.AllCaps) This filter will capitalize all the lowercase and titlecase letters that are added through edits. [InputFilter.LengthFilter](https://developer.android.com/reference/android/text/InputFilter.LengthFilter) This filter will constrain edits not to make the length of the text greater than the specified length. [LoginFilter](https://developer.android.com/reference/android/text/LoginFilter) *This class was deprecated in API level 30. Password requirements should not be hardcoded in clients. This class also does not handle non-BMP characters.* [LoginFilter.PasswordFilterGMail](https://developer.android.com/reference/android/text/LoginFilter.PasswordFilterGMail) *This class was deprecated in API level 30. Do not handle a user's Google password. Refer to [Google Help](https://support.google.com/accounts/answer/32040) for password restriction information.* [LoginFilter.UsernameFilterGMail](https://developer.android.com/reference/android/text/LoginFilter.UsernameFilterGMail) *This class was deprecated in API level 30. Do not encode assumptions about Google account names into client applications.* [LoginFilter.UsernameFilterGeneric](https://developer.android.com/reference/android/text/LoginFilter.UsernameFilterGeneric) This filter rejects characters in the user name that are not compatible with Google login. [NumberKeyListener](https://developer.android.com/reference/android/text/method/NumberKeyListener) For numeric text entry

<br />

As for all implementations of `https://developer.android.com/reference/android/text/method/KeyListener`, this class is only concerned with hardware keyboards. [TimeKeyListener](https://developer.android.com/reference/android/text/method/TimeKeyListener) For entering times in a text field.   

*** ** * ** ***

InputFilters can be attached to `https://developer.android.com/reference/android/text/Editable`s to constrain the changes that can be made to them.

## Summary

| ### Nested classes ||
|---|---|
| ` class` | `https://developer.android.com/reference/android/text/InputFilter.AllCaps` This filter will capitalize all the lowercase and titlecase letters that are added through edits. |
| ` class` | `https://developer.android.com/reference/android/text/InputFilter.LengthFilter` This filter will constrain edits not to make the length of the text greater than the specified length. |

| ### Public methods ||
|---|---|
| ` abstract https://developer.android.com/reference/java/lang/CharSequence` | ` https://developer.android.com/reference/android/text/InputFilter#filter(java.lang.CharSequence,%20int,%20int,%20android.text.Spanned,%20int,%20int)(https://developer.android.com/reference/java/lang/CharSequence source, int start, int end, https://developer.android.com/reference/android/text/Spanned dest, int dstart, int dend) ` This method is called when the buffer is going to replace the range `dstart ... dend` of `dest` with the new text from the range `start ... end` of `source`. |

## Public methods

### filter

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract CharSequence filter (CharSequence source, 
                int start, 
                int end, 
                Spanned dest, 
                int dstart, 
                int dend)
```

This method is called when the buffer is going to replace the range `dstart ... dend` of `dest` with the new text from the range `start ... end` of `source`. Return the CharSequence that you would like to have placed there instead, including an empty string if appropriate, or `null` to accept the original replacement. Be careful to not to reject 0-length replacements, as this is what happens when you delete text. Also beware that you should not attempt to make any changes to `dest` from this method; you may only examine it for context. Note: If <var translate="no">source</var> is an instance of `https://developer.android.com/reference/android/text/Spanned` or `https://developer.android.com/reference/android/text/Spannable`, the span objects in the <var translate="no">source</var> should be copied into the filtered result (i.e. the non-null return value). `https://developer.android.com/reference/android/text/TextUtils#copySpansFrom(android.text.Spanned,%20int,%20int,%20java.lang.Class,%20android.text.Spannable,%20int)` can be used for convenience if the span boundary indices would be remaining identical relative to the source.

<br />

| Parameters ||
|---|---|
| `source` | `CharSequence` <br /> |
| `start` | `int` <br /> |
| `end` | `int` <br /> |
| `dest` | `Spanned` <br /> |
| `dstart` | `int` <br /> |
| `dend` | `int` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence` | <br /> |