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+)*)*$
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 AZ and az 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.
我不知道salesforce.com如何验证电子邮件地址,但是由于您使用的是.NET,我建议您考虑一个电子邮件验证组件,例如我们的EmailVerify.NET,该组件符合当前的IETF标准(RFC 1123,RFC 2821,RFC 2822,RFC 3490,RFC 3696,RFC 4291,RFC 5321,RFC 5322和RFC 5336),并且不受ReDoS的困扰:如果需要,它甚至会检查被测试的电子邮件域的DNS记录, SMTP可用性,验证相关的邮箱,甚至可以知道目标邮件交换机是否为全部或者它是一次性/免费电子邮件地址提供商。
我不知道salesforce.com使用了什么(我认为你没有办法找到),但是b[A-Z0-9._%+-]+@[A-Z0-9.-]+.[AZ]{2,4}b
从这里开始是一个通用程序,应该适用于大多数情况。
上一篇: 匹配电子邮件检查