Using Client side JavaScript to ensure that phone numbers is in the correct format for Microsoft CRM 3.0 and 4.0

June 5, 2008
 
Place in the change event on the field that you want the phone number to be in the correct format.
var telephoneMaskRegularExpresion = new RegExp("[+]\\d\\d\\s[(]\\d[)]\\d\\d\\s\\d\\d\\d\\s\\d\\d\\d\\d","i");

var phoneNumberToValidate = crmForm.all.telephone1;

if(telephoneMaskRegularExpresion.test(phoneNumberToValidate.DataValue) != true)
{
    alert("Incorrect phone number format example of correct phone numbers  format is: +27 (0)55 555 5555 or +27 (0)55 555 5555");
    phoneNumberToValidate.DataValue="";
    phoneNumberToValidate.SetFocus();
}

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

 

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }


Follow

Get every new post delivered to your Inbox.