I have a need to validate Phone/Email data in Sage CRM 7.2d and found a help page using Entity Level Table Scripts to validate the data.
I took the code from the post originally written by Jeff Richards. The article can be found here https://community.sagecrm.com/partner_community/b/hints_tips_and_tricks/archive/2009/04/29/validating-phone-numbers-and-email-addresses.aspx
The code discussed in the article has been modified to the following:
function emailvalidation(x,y)
{
if (x.length>0)
{
re = /\S+@\S+\.\S+/;
if (!emailAddress.match(re))
{
Valid = false
ErrorStr = CRM.GetTrans("colnames",y)+ " ["+x+"] "+ CRM.GetTrans("GenCaptions","BadMailAddress");
}
}
}
function phonevalidation(x,y)
{
re = /^(\+\d{1,3}[- ]?)?\d{10}$/;
r = x.match(re);
if (r)
{
Valid = false;
ErrorStr = CRM.GetTrans("colnames",y)+ " ["+x+"] "+ CRM.GetTrans("Errors","InvalidIntegerValue");
}
}
function InsertRecord()
{
// Handle insert record actions here
emailvalidation(FormValues("emai_emailaddressbilling"),"emai_emailaddressbilling");
emailvalidation(FormValues("emai_emailaddressbusinessowner"),"emai_emailaddressbusinessowner");
emailvalidation(FormValues("emai_emailaddressdoctor"),"emai_emailaddressdoctor");
emailvalidation(FormValues("emai_emailaddressdtd"),"emai_emailaddressdtd");
emailvalidation(FormValues("emai_emailaddresspracadmin"),"emai_emailaddresspracadmin");
emailvalidation(FormValues("emai_emailaddresssales"),"emai_emailaddresssales");
emailvalidation(FormValues("emai_emailaddresssupport"),"emai_emailaddresssupport");
phonevalidation(FormValues("phon_areacodebusiness"),CRM.GetTrans("Link_CompPhon","Business"));
phonevalidation(FormValues("phon_numberbusiness"),CRM.GetTrans("Link_CompPhon","Business"));
phonevalidation(FormValues("phon_areacodefax"),CRM.GetTrans("Link_CompPhon","Fax"));
phonevalidation(FormValues("phon_numberfax"),CRM.GetTrans("Link_CompPhon","Fax"));
phonevalidation(FormValues("phon_areacodepracticeadmin"),CRM.GetTrans("Link_CompPhon","PracticeAdmin"));
phonevalidation(FormValues("phon_numberpracticeadmin"),CRM.GetTrans("Link_CompPhon","PracticeAdmin"));
phonevalidation(FormValues("phon_areacodecellphonenumber"),CRM.GetTrans("Link_CompPhon","CellphoneNumber"));
phonevalidation(FormValues("phon_numbercellphonenumber"),CRM.GetTrans("Link_CompPhon","CellphoneNumber"));
phonevalidation(FormValues("phon_areacodemodem"),CRM.GetTrans("Link_CompPhon","Modem"));
phonevalidation(FormValues("phon_numbermodem"),CRM.GetTrans("Link_CompPhon","Modem"));
phonevalidation(FormValues("phon_areacodetel2"),CRM.GetTrans("Link_CompPhon","Tel2"));
phonevalidation(FormValues("phon_numbertel"),CRM.GetTrans("Link_CompPhon","Tel2"));
phonevalidation(FormValues("phon_areacodetel3"),CRM.GetTrans("Link_CompPhon","Tel3"));
phonevalidation(FormValues("phon_numbertel3"),CRM.GetTrans("Link_CompPhon","Tel3"));
phonevalidation(FormValues("phon_areacodetel4"),CRM.GetTrans("Link_CompPhon","Tel4"));
phonevalidation(FormValues("phon_numbertel4"),CRM.GetTrans("Link_CompPhon","Tel4"));
}
function PostInsertRecord()
{
// Handle post insert record actions here
}
function UpdateRecord()
{
// Handle update record actions here
emailvalidation(FormValues("emai_emailaddressbilling"),"emai_emailaddressbilling");
emailvalidation(FormValues("emai_emailaddressbusinessowner"),"emai_emailaddressbusinessowner");
emailvalidation(FormValues("emai_emailaddressdoctor"),"emai_emailaddressdoctor");
emailvalidation(FormValues("emai_emailaddressdtd"),"emai_emailaddressdtd");
emailvalidation(FormValues("emai_emailaddresspracadmin"),"emai_emailaddresspracadmin");
emailvalidation(FormValues("emai_emailaddresssales"),"emai_emailaddresssales");
emailvalidation(FormValues("emai_emailaddresssupport"),"emai_emailaddresssupport");
phonevalidation(FormValues("phon_areacodebusiness"),CRM.GetTrans("Link_CompPhon","Business"));
phonevalidation(FormValues("phon_numberbusiness"),CRM.GetTrans("Link_CompPhon","Business"));
phonevalidation(FormValues("phon_areacodefax"),CRM.GetTrans("Link_CompPhon","Fax"));
phonevalidation(FormValues("phon_numberfax"),CRM.GetTrans("Link_CompPhon","Fax"));
phonevalidation(FormValues("phon_areacodepracticeadmin"),CRM.GetTrans("Link_CompPhon","PracticeAdmin"));
phonevalidation(FormValues("phon_numberpracticeadmin"),CRM.GetTrans("Link_CompPhon","PracticeAdmin"));
phonevalidation(FormValues("phon_areacodecellphonenumber"),CRM.GetTrans("Link_CompPhon","CellphoneNumber"));
phonevalidation(FormValues("phon_numbercellphonenumber"),CRM.GetTrans("Link_CompPhon","CellphoneNumber"));
phonevalidation(FormValues("phon_areacodemodem"),CRM.GetTrans("Link_CompPhon","Modem"));
phonevalidation(FormValues("phon_numbermodem"),CRM.GetTrans("Link_CompPhon","Modem"));
phonevalidation(FormValues("phon_areacodetel2"),CRM.GetTrans("Link_CompPhon","Tel2"));
phonevalidation(FormValues("phon_numbertel"),CRM.GetTrans("Link_CompPhon","Tel2"));
phonevalidation(FormValues("phon_areacodetel3"),CRM.GetTrans("Link_CompPhon","Tel3"));
phonevalidation(FormValues("phon_numbertel3"),CRM.GetTrans("Link_CompPhon","Tel3"));
phonevalidation(FormValues("phon_areacodetel4"),CRM.GetTrans("Link_CompPhon","Tel4"));
phonevalidation(FormValues("phon_numbertel4"),CRM.GetTrans("Link_CompPhon","Tel4"));
}
function DeleteRecord()
{
// Handle delete record actions here
}
The code above however is not validating against the inputted data on either the Company or Person table. If anyone could possibly assist with getting this to work I would greatly appreciate it.