Advertisements
Home > CRM, CRM 2011, CRM 4.0, JScript > Email format validation in CRM

Email format validation in CRM

Hi,

The out of the box CRM Email field type does not validate whether the given email is ending with “.com”,”.in”,etc… (Refer below)

  • rajeevpentyala@live  (Its a valid email format as per out of the box CRM Email Type validation)

We can validate all the metrics of Email format by using below steps.

Step 1:-

  • Create a new “Field” (i.e.,new_emailaddress1) of type nvarchar(100)
  • Since the field is normal field, we have to format the field to look like “Email”
  • Place below script in form ‘onload’ event

    var emailTextBox = crmForm.all.new_emailaddress1;

//Set the field style similar to ‘Email’ (i.e., Blue forecolor and Underline)
emailTextBox.style.color = “#0000ff”;
emailTextBox.style.textDecoration = “underline”;

//Attach ‘on double click’ event
emailTextBox.attachEvent(“ondblclick”, openEmail);
function openEmail() { if (emailTextBox.DataValue != null) document.location = “mailto:” + emailTextBox.DataValue; }

Step 2 (Email Validation) :-

  • We can validate email format either in form’s ‘onsave’ event (or) field’s ‘onchange’ event
  • Register below function as per your requirement (i.e.,Either in ‘onsave’ or ‘onchange’)

function ValidateEmail() {
var emailID = crmForm.all.emailaddress1.DataValue;

if ((emailID.indexOf(“@”) > 0 && (emailID.lastIndexOf(“@”) != (emailID.length – 1))) || (1 == 1)) {
if (emailID.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
}
else {
alert(“You must enter a valid e-mail address.”);
crmForm.all.emailaddress1.SetFocus();
event.returnValue = false;
}
}
}

Hope it helps 🙂

Advertisements
  1. mahesh
    October 28, 2011 at 9:36 PM

    Great stuff!!!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: