How to perform validation in EditText in Android?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
47 views
Hello! My task is to develop a EditText view in which we introduce the phone. In the Edit Text we see a hint of this type: +7(___)___-__-__ the User starts to enter digits just after 7 and as you enter the underscores remain. I don't know where to start to solve this problem, and I need a hint in which direction I should go. Maybe you have a ready-made solution and ask them to share)
by | 47 views

2 Answers

0 like 0 dislike
There is a good solution: https://github.com/RedMadRobot/input-mask-android. But if you really want self - view in the direction of the InputFilters
by
0 like 0 dislike
This is done using a TextWatcher listener:
editText.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub } });

With every change of the input field You are in one of these methods format the string according to Your pattern.
UPD. If you want to find the snippet under formatting a phone number I wrote the same already. In short, the formatting can be done using Google libphonenumber library.
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked Jun 3, 2019 by andrei500
110,608 questions
257,186 answers
0 comments
35,389 users