Hi guys,
I wrote javascript to format the phone number as 111-111-1111, and also if the user didnt put in 10 numbers an alert will pop up. But after I save the phone number, then I clear the field and try to save agai, an error message will pop up says 'Null' is null or not an object. How can I solve this problem cuz user might want to clear the existing phone number.

Below is my code.
function FormatPhoneNumber(context)
{
var oField = context.getEventSource().getValue();
var sAllNumeric = oField.replace(/[^0-9]/g, "");
var sFormattedPhoneNumber;
if(typeof(oField)!= "undefined" && oField!= null)
{
switch (sAllNumeric.length)
{
case "0833211139".length:
sFormattedPhoneNumber = sAllNumeric.substring(0,3) + "-"+ sAllNumeric.substring(3,6) +"-"+ sAllNumeric.substring(6)
break;
default:
alert("Phone/Fax must contain 10 numbers.")
break;
}
context.getEventSource().setValue(sFormattedPhoneNumber);
}
}
*This post is locked for comments
I have the same question (0)