/ Published in: JavaScript

Generic function - Pass the context to the function for use with any field
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function FormatPhoneNumber(eContext) { // Get the field that fired the event. var oField = eContext.getEventSource().getValue(); var sTmp = oField // Validate the field information. if (typeof(oField) != "undefined" && oField != null) { // Remove any non-numeric characters. var sTmp = oField.replace(/[^0-9]/g, ""); // If the number has a valid length, format the number. switch (sTmp.length) { case "4105551212".length: oField = "(" + 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; } } }
Comments
