Here is something I wrote last year to demonstrate the concept, it is table-independent so it could be called via BPM from any table.
Enhancing for International would still have to be done. for now it returns an error if there are not 10 numeric digits after stripping out punctuation chars.
Good luck!
Chris
ps - I will post it to "Files" too.
/*
Procedure FormatPhone.p - Given phone string 1234567890[x123...], validate and return it formatted.
Usage:
run FormatPhone.p (INPUT vcphone, OUTPUT vcPhone2) NO-ERROR.
if error-status:error then do:
/* error handling code, message to user, etc. */
end.
*/
def input param vcPhone as char no-undo.
def output param vcPhone2 as char no-undo.
def var vcExt as char no-undo.
def var vdTemp as decimal no-undo.
def var vcbad as char no-undo.
def var delim as char no-undo.
def var badchars as char no-undo initial "-().". /* add others if needed but leave "X" to delimit the extension */
def var i as int no-undo.
do i = 1 to length(badchars):
vcBad = substring(badchars, i, 1).
vcphone = replace(vcPhone, vcBad, "").
end.
if length(vcPhone) > 10 then do:
/* multiple character delim didn't work, convert to "x" */
if index(vcPhone, "Extension") > 0 then vcPHone = replace(vcPhone, "Extension", "x").
else if index(vcPhone, "Ext") > 0 then vcPhone = replace(vcPhone, "Ext", "x").
else if index(vcPhone, "Ex") > 0 then vcPhone = replace(vcPhone, "Ex", "x").
if index(vcPhone, "x") > 0 then delim = "x".
if delim > ""
then assign
vcExt = trim(entry(2, vcPhone, delim))
vcPhone = trim(entry(1, vcPhone, delim))
vcExt = replace(vcExt, ".", "")
vcPhone = replace(vcPhone, Delim, ""). /* strip out the "X" */
end.
if vcPhone > "" and length(vcPhone) <> 10 then return error "Phone# must be 10 numeric digits".
assign vdTemp = DECIMAL(vcPhone) no-error.
if error-status:error then do: /* not an integer */
return error "Non-numeric digits in phone number: " + vcPhone.
end.
else do:
vcPhone2 = string(vcPhone,"(999)999-9999") + (if vcExt > "" then "x" + vcExt else "").
end.
Enhancing for International would still have to be done. for now it returns an error if there are not 10 numeric digits after stripping out punctuation chars.
Good luck!
Chris
ps - I will post it to "Files" too.
/*
Procedure FormatPhone.p - Given phone string 1234567890[x123...], validate and return it formatted.
Usage:
run FormatPhone.p (INPUT vcphone, OUTPUT vcPhone2) NO-ERROR.
if error-status:error then do:
/* error handling code, message to user, etc. */
end.
*/
def input param vcPhone as char no-undo.
def output param vcPhone2 as char no-undo.
def var vcExt as char no-undo.
def var vdTemp as decimal no-undo.
def var vcbad as char no-undo.
def var delim as char no-undo.
def var badchars as char no-undo initial "-().". /* add others if needed but leave "X" to delimit the extension */
def var i as int no-undo.
do i = 1 to length(badchars):
vcBad = substring(badchars, i, 1).
vcphone = replace(vcPhone, vcBad, "").
end.
if length(vcPhone) > 10 then do:
/* multiple character delim didn't work, convert to "x" */
if index(vcPhone, "Extension") > 0 then vcPHone = replace(vcPhone, "Extension", "x").
else if index(vcPhone, "Ext") > 0 then vcPhone = replace(vcPhone, "Ext", "x").
else if index(vcPhone, "Ex") > 0 then vcPhone = replace(vcPhone, "Ex", "x").
if index(vcPhone, "x") > 0 then delim = "x".
if delim > ""
then assign
vcExt = trim(entry(2, vcPhone, delim))
vcPhone = trim(entry(1, vcPhone, delim))
vcExt = replace(vcExt, ".", "")
vcPhone = replace(vcPhone, Delim, ""). /* strip out the "X" */
end.
if vcPhone > "" and length(vcPhone) <> 10 then return error "Phone# must be 10 numeric digits".
assign vdTemp = DECIMAL(vcPhone) no-error.
if error-status:error then do: /* not an integer */
return error "Non-numeric digits in phone number: " + vcPhone.
end.
else do:
vcPhone2 = string(vcPhone,"(999)999-9999") + (if vcExt > "" then "x" + vcExt else "").
end.
--- In vantage@yahoogroups.com, Joe Rojas <jrojas@...> wrote:
>
> Hi All,
>
>
>
> Before I recreate the wheel, has anyone create a customization to
> enforce formatting of a phone numbers?
>
> If yes, would you be willing to share it? :)
>
>
>
> I guess it would have to be "smart" enough to be ridged for US phone
> numbers but able to be relaxed for non-US numbers.
>
>
>
>
>
>
>
>
>
>
> Joe Rojas | Director of Information Technology | Mats Inc
> dir: 781-573-0291 | cell: 781-408-9278 | fax: 781-232-5191
> jrojas@... | www.matsinc.com Ask us about our clean, green and beautiful matting and flooring
>
>
> This message is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake. Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company.
>
>
> [Non-text portions of this message have been removed]
>