Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Salesforce.com validate Email Fields?

I'm trying to store email addresses in Salesforce.com from another service that allows invalid email addresses to be specified. If one of those bad invalid email addresses is sent to Salesforce.com via their Web Services API, Salesforce.com will prevent the record from saving with an INVALID_EMAIL_ADDRESS error code.

I can't find any documentation on how to disable validation on Email fields, so it looks like I'll need to validate them in my integration and pull out those that fail. Does anyone know the validation process Salesforce.com uses to determine if an email address is valid? All I have right now is a Regex, but I'd like it to match Salesforce.com's process.

EDIT: For reference, here is my Regex (I'm using C#/.NET):

^(\w|[!#$%'*+-/=?^_`\{\}~.&])+@\w+([-.]\w+)*\.\w+([-.]\w+)*([,;]\s*\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)*$
like image 567
Technetium Avatar asked Dec 28 '22 03:12

Technetium


1 Answers

Summary: we're using the following .NET RegEx:

const string SFEmailRegExPattern = @"^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";

If you can believe SF's own documentation then:

For the local part of the email address we accept the following characters. The local part is anything before the @ sign.

abcdefg.hijklmnopqrstuvwxyz!#$%&'*/=?^_+-`{|}~0123456789

Note: The character dot . is supported; provided that it is not the first or last character in the local-part

For the domain part of the email address we accept. The domain part is anything after the @ in an email address:

0-9 and A-Z and a-z and dash -

A couple of people have coded this up as a Java regex as:

String pat = '[a-zA-Z0-9\\.\\!\\#\\$\\%\\&\\*\\/\\=\\?\\^\\_\\+\\-\\`\\{\\|\\}\\~\'._%+-]+@[a-zA-Z0-9\\-.-]+\\.[a-zA-Z]+';

although to me this looks like it fails to reject an email that starts with a "." so isn't perfect.

like image 116
MrBlueSky Avatar answered Mar 07 '23 07:03

MrBlueSky