I have been trying to figure the appropriate way to represent phone number and amount. Let me be specific, I have a user form where the user are supposed to fill their phone number and amount. I am from Nepal and we usually have the phone number in format 01-4444445 or 023-454566. I wonder how can I do this? In addition, in the amount field, i wish to display amount in this format 1,000,000 and so on. For example, when the user enters four digit comma sign should be automatically added to the field. Plz, suggest me the way I can do this. I have been trying this since a week. Thanks in advance.
Call this function from TextWatcher (For NTC Prepaid validation) "^(984|986)\d{7}$" this means phone number starts with 984 or 986 and after that there is 7 digits i.e. total 10 digits
phoneNumber.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(!isValidNumber(s.toString())){
isnumbervalid=false;
phoneNumber.setTextColor(Color.parseColor("#F44336"));
}else {
isnumbervalid=true;
phoneNumber.setTextColor(Color.parseColor("#000000"));
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
private boolean isValidNumber(String phonenumber) {
String PHONE_PATTERN = "^(984|986)\\d{7}$";
Pattern pattern = Pattern.compile(PHONE_PATTERN);
Matcher matcher = pattern.matcher(phonenumber);
return matcher.matches();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With