Skip to content

johancyprich/FormatPhone

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FormatPhone

Version: 1.2.0
May 15, 2015
License: The MIT License (MIT)
Author: Johan Cyprich (jcyprich@live.com)

JavaScript function that formats a phone number according a user selected style. The function extracts all of the numbers from the tel string and tries to build a phone number. If the number of digits extracted is not 10, then the function will return an error.

Function Parameters:

tel (in) - phone number to be formatted
style (in) - the format to write the phone number as. The options for style are the following:

style format
0 No formatting
1 ###-###-####
2 ###.###.####
3 ### ### ####
4 (###) ###-####
5 (###) ###.####
6 (###) ### ####
7 +??#-###-###-####
8 +??# (###) ###-####
9 +??# (###) ### ####
10 +??# ### ### ####
11 +??#.###.###.####
12 # ### ###-####
  where # is a number
        ? is an optional number

Return Value:

If a valid phone number was created, it will be returned as a string. Otherwise, the string returned will be "*** ERROR ***" if the phone number could not be parsed. If an empty string is being parsed, the function will exit and return the empty string instead of the error message.

How to Install Script in uPlan

  1. Open uPlan.
  2. Right click on Functions and select New Function -> JavaScript -> String.
  3. Name the function FormatPhone.
  4. Right click on the function and select New Parameter -> String.
  5. Enter tel for variable name.
  6. Right click on the function again and select New Parameter -> Number.
  7. Enter style for the variable name.
  8. Copy and paste JavaScript code from XMPie/FormatPhone.js into the FormatPhone function in uPlan (you don't need to include the comments.

Usage

In the ADOR object, use the function as

     FormatPhone (@{var_phone}, @{var_style})

Example

See FormatPhone.plan for an example.

About

Formats a phone number to a specified style. JavaScript function for HTML pages or XMPie uStore dynamic documents.

Resources

License

Stars

Watchers

Forks

Packages

No packages published