This entry was posted on Monday, January 28th, 2008 at 2:22 pm and is filed under Customizations. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Email address field validation – Regular Expressions
Now this isn’t a perfect example, but this is an easy implementation to check the format of email addresses that are entered into Microsoft CRM. Like i mentioned before this isn’t perfect, but does a decent job without alot of work.
Through a (regex)or regular expression you can make light work of data validation in CRM. Below is a sample that first looks up the value of the emailaddress1 field. Then it simply compares the text entered against the validEmail function, and returns whether the email matches or doesn’t match the criteria specified.
In this case if it doesn’t match the format then it basically states that the email entered is not in the correct format. This code below can actually be changed to whatever you desire, and can easily be copied to the onchange event of any field that you wish to run email validation on. This is just a simple example of a regular expressions and this can be built upon to provide much more complex testing. Hope it helps. Take Care!
var str = crmForm.all.emailaddress1.value;
if (!validEmail(str)) {
alert (’This Email is not in the correct format. Example: nicholasc@saratogaus.com’)
}
function validEmail(str) { return str.match(/^[a-z0-9]+([-_\.]?[a-z0-9])+@[a-z0-9]+([-_\.]?[a-z0-9])+\.[a-z]{2,4}/i); }
Leave a Reply
You must be logged in to post a comment.
