I am considering below cases to remove garbage values ,or space bracket from a telephone number string.
Below are the examples I am considering.
//Ignore Special char
phone = "+1-555-555-1234"
result = "15555551234"
phone = "1(800)555-0199"
result = "18005550199"
//Ignore Space
phone="555 555 1234"
result = "5555551234"
//If phone number contains spaces,parenthesis or some garbage character only consider digits.
phone = "9898871234567)"
result = "9898871234567"
//If + and parenthesis symbol is present
phone = "+11 111 111"
result = "11111111"
phone= "(22) 222-222"
result = "22222222"
//If hyphen is present
phone = "(22) 222-222"
result = "22222222"
How can I easliy achive this in javascript using regex?