Version: 1.2.0
May 15, 2015
License: The MIT License (MIT)
Author: Johan Cyprich ([email protected])
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.
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
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.
- Open uPlan.
- Right click on Functions and select New Function -> JavaScript -> String.
- Name the function FormatPhone.
- Right click on the function and select New Parameter -> String.
- Enter tel for variable name.
- Right click on the function again and select New Parameter -> Number.
- Enter style for the variable name.
- Copy and paste JavaScript code from XMPie/FormatPhone.js into the FormatPhone function in uPlan (you don't need to include the comments.
In the ADOR object, use the function as
FormatPhone (@{var_phone}, @{var_style})
See FormatPhone.plan for an example.