This library helps to format the input (in EditText) while the user types. Currently this library supports any formats without dash (-) operator in output, as it uses dash (-) operator to specify the format.
Note :
Due to a bug in emulator Check this answer,
If no input type is mentioned (example: as below), then characters might be duplicated
android:inputType="number"
Add the following dependency to app/build.gradle or module/build.gradle file.
implementation 'com.androidwidgets:formatedittext:0.2.0'
<FormatEditText
android:id="@+id/ed_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" />
-
If you need only format (when no validation required)
final FormatEditText editText = findViewById(R.id.ed_text); editText.setFormat("<any format>");
-
If you need validation
final FormatEditText editText = findViewById(R.id.ed_text); editText.setValidator(new Validator(), new ValidationListener()); editText.setFormat("<any format>");
Implement the following interface to define your own Validator and ValidationListener.
FormatTextWatcher.Validator
FormatTextWatcher.ValidationListener
Validator.validate() method receives 2 inputs as parameters, Formatted and Unformatted inputs respectively, to easy the validation steps. Based on the validate response (true/false), methods (showSuccess()/showError()) from ValidationListener will get called.
Credit Card Type | Format |
---|---|
Visa | ---- ---- ---- ---- |
Visa Electron | ---- ---- ---- ---- |
American Express | ---- ------ ----- |
MasterCard | ---- ---- ---- ---- |
Maestro | ---- ---- ----- |
---- ------ ----- | |
---- ---- ---- ---- |
Date Examples | Format |
---|---|
22/Feb/2019 | --/---/---- |
22/Feb/19 | --/---/-- |
22-Feb-2019 | Not supported yet |
22/02/2019 | --/--/---- |
22/02/19 | --/--/-- |
Mobile number formats (Reference here)
Country | Digits | Mobile number Example | Format |
---|---|---|---|
India | 10 digits long | +91 AAAAA BBBBB | +91 ----- ----- |
Hong Kong and Macau | 8 digits long | XXXX YYYY | ---- ---- |
Japan | (0AA) NXX XXXX | (---) --- ---- |
Time example | Format |
---|---|
10:50:45 am | --:--:-- -- |
Copyright 2020 Gowtham Shanmugaraj Ganesan
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.