Sign inSign up

mysmartbus/format_phonenumberdisplay

By mysmartbus

•Updated over 8 years ago

Validates a U.S.A. phone number and formats it for display

Image
0

200

mysmartbus/format_phonenumberdisplay repository overview

This is an Openfaas⁠ function.

NOTES:

  1. Currently only handles 7, 10 and 11 digit phone numbers as used in the United States.
  2. Will consider a phone number with a country calling code invalid due to length of phone number. See http://en.wikipedia.org/wiki/List_of_country_calling_codes⁠ to fix this
  3. Also assumes that only 1-800 numbers will use letters
  4. Cannot handle international (Europe, France, Belgum) phone numbers

Validation Examples:

  1. (234) 235 5678 is valid
  2. (234) 911 5678 is invalid, because the exchange code cannot be in the form N11.
  3. (123) 234 5678 is invalid, because NPA (Area Code) cannot begin with "0" or "1"
  4. (291) 234 5678 is invalid, because the second digit of an area code cannot be "9"

Sources:
Telephone Numbers In the United States (Wikipedia)⁠ List_of_North_American_Numbering_Plan_area_codes (Wikipedia)⁠

Formatting Examples:

InputOutputValid Input
717 123-4567(717) 123-4567true
7171234567(717) 123-4567true
1234567123-4567true
1-800-CALL-ME21-800-CAL-LME2true
1800CALLME21-800-CAL-LME2true
1800CALLME1800CALLMEfalse (Exchange Code [First digit less than 2])
123456123456false (Only has 6 digits)

Returns:
If phone number is valid, will be formatted phone number
If phone number is invalid, will be the phrase 'Invalid(): ' followed by the phone number as it was received by the function. will be the reason the phone number failed validation.

Usage:

  1. curl -d "1-800-EXAMPLE" http://127.0.0.1:8080/function/formatphonenumberdisplay⁠
  2. curl -d "1-800-EXAMPLE3" http://127.0.0.1:8080/function/formatphonenumberdisplay⁠
  3. curl -d "5110170" http://192.168.17.107:8080/function/formatphonenumberdisplay⁠

Output:

  1. 1-800-392-6753
  2. Invalid (Length): 1-800-EXAMPLE3
  3. Invalid (Exchange Code [Cannot be x11]): 5110170

Tag summary

Content type

Image

Digest

Size

24.6 MB

Last updated

over 8 years ago

docker pull mysmartbus/format_phonenumberdisplay