Implementing conditional inside UDF?
Hello,
I have UDF I wrote for formatting phone numbers;
<cfscript>
/* Converts 800 555 1212 into (800) 555-1212*/
function phix(str)
{
/*Get rid of the spaces, for now 8005551212*/
VAR pn=ReReplaceNoCase(str,'[-, ,.,(,)]','','ALL');
/*Insert Left Parenthesis in str*/
VAR pn2=INSERT('(',pn,0);
/*Insert Right Parenthesis in str*/
VAR pn3=INSERT(')',pn2,4);
/*Insert Space after Right Parenthesis in str*/
VAR pn4=INSERT(" ",pn3,5);
/*Insert Dash after Prefix in str*/
VAR pn5=INSERT("-",pn4,9);
RETURN pn5;
}
</cfscript>
And I am wanting to apply it only if the value of the str input is numeric. The field in the form is not restrictive, nor should it be - things like "ext 123" or "daytime" might need to be input as well as the phone number.
So I am trying to add an IF IsNumeric(str) to the function so it will only execute if the input of str is a number string. So far none of the examples of conditionals within function scripts seems to work when I replicate their syntax. I'm sure it's a simple thing, hopefully one of you can help out.
So, to recap... If the input str is digits only, apply function, else do nothing to the str.
Thanks!
