// Get the field that fired the event.
var oField = event.srcElement;
// Validate the field information.
if (typeof (oField) != "undefined" && oField != null) {
// get any extension and then store it and remove if from phone number....
var extension = "";
try {
if (oField.DataValue.toLowerCase().indexOf("x") > 5)
extension = oField.DataValue.substring(oField.DataValue.toUpperCase().indexOf("X"));
oField.DataValue = oField.DataValue.substring(0, oField.DataValue.toLowerCase().indexOf("x"));
}
catch (Error) {
extension = "";
}
// Remove any non-numeric characters.
var sTmp = oField.DataValue.replace(/[^0-9]/g, "");
// If the number has a valid length, format the number.
switch (sTmp.length) {
case "4105551212".length:
oField.DataValue = "" + sTmp.substr(0, 3) + "-" +
sTmp.substr(3, 3) + "-" + sTmp.substr(6, 4);
break;
case "5551212".length:
oField.DataValue = sTmp.substr(0, 3) + "-" +
sTmp.substr(3, 4);
break;
}
if (extension.length > 0) oField.DataValue += extension;
}
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment