Reputation: 13
I'm trying to parse a user input from an EditText of number type as a phone number but its not being formatted correctly. On the action used to call the number it tells me the number is invalid. Is this code correctly parsing it for the call intent?
LayoutInflater inflater = LayoutInflater.from(PbfSampleApplication.this);
View v = inflater.inflate(R.layout.activity_main, null);
EditText innerView = (EditText)v.findViewById(R.id.number);
String actualnum="tel:"+innerView.getText().toString().trim();
Upvotes: 0
Views: 51
Reputation: 450
I recommend you trying:
String.valueOf(innerView.getText());
instead of:
toString()
Upvotes: 2
Reputation: 3422
You can validate mobile number using below code:
private boolean isValidPhone(String s) {
String expression = "^[7-9]{1}[0-9]{9}$";
CharSequence inputString = s;
Pattern pattern = Pattern.compile(expression);
Matcher matcher = pattern.matcher(inputString);
if (matcher.matches())
{
return true;
}
else{
return false;
}
}
Upvotes: 0