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 🙂
Great stuff!!!