Return to Snippet

Revision: 62791
at March 13, 2013 07:52 by chetkloss


Initial Code
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;
			 }
	}
}

Initial URL


Initial Description
Generic function - Pass the context to the function for use with any field

Initial Title
Format a US Phone Numner

Initial Tags
phone, number, format

Initial Language
JavaScript