1

I've got several types of phone numbers as a String:

For example:

+49 176 666 454 414 +49(176)-666454414 +49176-666454414 

But I would like to convert every type of phone number like the following : +4917622265414

Basically only digits.

How can I do that in dart? Aynone has an idea? I could do like below but I'm sure there must be a better way to do that.

String result = gfg.replaceAll(" ", ""); String result = gfg.replaceAll("(", ""); String result = gfg.replaceAll(")", ""); String result = gfg.replaceAll("-", ""); 

Thanks :)

1 Answer 1

4

You can use regex to extract all digit from the string

String result = gfg.replaceAll(new RegExp(r'[^0-9]'),''); 

And add the + at the begining

result = "+$result"; 

Does it help you ?

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Abdel That's what I was looking for :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.