MaskFormatter
MaskFormatter adds mask functionality to your EditText. It will prevent user from inserting not allowed signs, and format input as well.
Mask should be built from characters listed below (java regex associated to character given after colon):
'9': '[0-9]', '8': '[0-8]', '7': '[0-7]', '6': '[0-6]', '5': '[0-5]', '4': '[0-4]', '3': '[0-3]', '2': '[0-2]', '1': '[0-1]', '0': '[0]', '*': '.', 'W': '\W', 'd': '\d', 'D': '\D', 's': '\s', 'S': '\S', 'A': '[A-Z]', 'a': '[a-z]', 'Z': '[A-ZÇÀÁÂÃÈÉÊ?ÌÍÎ?ÒÓÔÕÙÚÛ?]', 'z': '[a-zçáàãâéèê?íì?îóòôõúù?üû]', '@': '[a-zA-Z]', '#': '[a-zA-Zçáàãâéèê?íì?îóòôõúù?üûÇÀÁÂÃÈÉÊ?ÌÍÎ?ÒÓÔÕÙÚÛ?]', '%': '[A-Z0-9]', 'w': '[a-zA-Z0-9]'
Usage
In your build.gradle
:
dependencies {
compile 'com.azimolabs.maskformatter:maskformatter:0.2'
}
Library is distributed via jCenter Maven repository. Make sure that you have it in your root gradle config:
allprojects {
repositories {
jcenter()
}
}
Then you can use it like this:
public MainActivity extends Activity {
private static final IBAN_MASK = "AA 99 9999 AAAA wwww wwww wwww";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sample_layout);
EditText ibanEditText = (EditText) findViewById(R.id.etIban);
MaskFormatter ibanMaskFormatter = new MaskFormatter(IBAN_MASK, ibanEditText);
ibanEditText.addTextChangedListener(ibanMaskFormatter);
}
}
And make sure that you disabled suggestions from used EditText:
<EditText
android:id="@+id/etIban"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text|textNoSuggestions" />
License
Copyright (C) 2016 AzimoLabs
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.