- Phone number normalizing - c oding help
- Posted by Ridhima Sood on September 15th, 2006
hi
I am using this code to normaliza the phone number. However i also want it
to normalize if the phonne number is in the format 021abcdef or 021 abcdeff.
Can someone please advice me what i need to amend to this code to get this
functionality going.
Kind Regards
Ridhima
// Get the field that fired the event.
var oField = event.srcElement;
// Validate the field information.
if (typeof(oField) != "undefined" && oField != null)
{
// Remove any nonnumeric characters.
var sTmp = oField.DataValue.replace(/[^0-9]/g, "");
// If the number has a valid length, format the number.
switch (sTmp.length)
{
case "555121223".length:
oField.DataValue = "+64 " + sTmp.substr(1, 2) + " " + sTmp.substr(3,3)
+ " " + sTmp.substr(6,3);
break;
case "5551212233".length:
oField.DataValue = "+64 " + sTmp.substr(1, 2) + " " + sTmp.substr(3,3)
+ " " + sTmp.substr(6,4);
break;
}
}
- Posted by chad.buser@ncsi.cc on September 15th, 2006
here is a script I used succesfully, note that there are 2:
// Original
// Attempt to auto-format basic United States phone numbers. This method
supports
// 7 and 10 digit numbers. Example: (410) 555-1212
// Get the field that fired the event
var oField = event.srcElement;
// If the field exists and is not null
if (typeof(oField) != "undefined" && oField != null)
{
// Remove any non-numeric characters
var sTmp = oField.DataValue.replace(/[^0-9]/g, "");
// If the number is a length we expect and support, 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;
}
}
// Updated 27 Jan 2006 to support 11 digit numbers
// Attempt to auto-format basic United States phone numbers. This method
supports
// 7, 10 & 11 digit numbers. Example: (410) 555-1212
// Get the field that fired the event
var oField = event.srcElement;
// If the field exists and is not null
if (typeof(oField) != "undefined" && oField != null)
{
// Remove any non-numeric characters
var sTmp = oField.DataValue.replace(/[^0-9]/g, "");
// If the number is a length we expect and support, 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;
case "14105551212".length:
oField.DataValue = sTmp.substr(0, 1) + "(" + sTmp.substr(1, 3) + ") "
+ sTmp.substr(4, 3) + "-" + sTmp.substr(7, 4);
break;
}
}
"Ridhima Sood" wrote:
- Posted by Ridhima Sood on September 17th, 2006
hi Chad
would this allow me to use alpha characters as well...because that is the
issue i am struggling with 
Kind Regards
Ridhima
"chad.buser@ncsi.cc" wrote:
- Posted by Darin Sipe on September 18th, 2006
Ridhima,
The code we use to do this we pulled form the book, "Working with
Microsoft Dynamics CRM 3.0" by Snyder and Steger (Microsoft Press).
I am unsure as to whether I can post this code as it is in their book (they
might what you to by the book). I suggest you do as it is a great resource
for CRM. Their sample code (which can also be downloaded) is very helpful,
especially for what you are asking here.
"Ridhima Sood" wrote:
- Posted by Ridhima Sood on September 19th, 2006
Thanks Darin. I will try and check out the book in a library or something.
Are you able to modify my code ... my email is ridhima.sood@mobile-mentor.com
"Darin Sipe" wrote: