function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
suresh_cssuresh_cs 

Salesforce default Email Validation rules/specification

Hi.

 

One of my client needs to know how an Email Address is validated

by salesforce,because the same validation rule /specification should be done

with another application/system the client uses.

 

This is to balance the Email validation  specification  in both systems/application.

 

Thanks

suresh

hisrinuhisrinu

I think the format is *@*.*

 

Where * can be 1 or more characters

Michael BarrowMichael Barrow

Do you know of a way to create a validation rule for a text field that requires it to be a valid email address? My app needs the field to be text because there are other records sharing that field for other purposes, so I can't change the field type to email address.

 

Thanks,

Michael

suresh.csksuresh.csk

Michael

 

here we go....

 

Using regex fucntion we can fix your issue.

 

Create a validation rule  like this

 

NOT(REGEX( testfield__c ,'([a-zA-Z0-9_\\-\\.]+)@((\\[a-z]{1,3}\\.[a-z]{1,3}\\.[a-z]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})'))

 

testfield__c is the fieldname which you want to modify before implement.

 

This worked for me.Let me know if you have any issues.

 

cheers

suresh

Michael BarrowMichael Barrow

suresh:

 

Thanks for your help with this!

 

Michael

Nikhil MoreNikhil More

Can something similar be implemented to validate an email address while inviting customers from standard chatter screen. I want to restrict the users with certain domain from registering as external chatter users. I can not try invite co workers and so only option I can have is validation or a trigger.. Any hints on validations..

 

TLFTLF

I'd probably do this with an Apex trigger and use the Pattern and Matcher classes to pass the incoming email address through the following regular expression (you'll need to escape the \ by doubling them when you convert it to a string in Apex code):

 

([a-zA-Z0-9_\-\.]+)@(((\[a-z]{1,3}\.[a-z]{1,3}\.[a-z]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3}))

 

This is a very slight modification to the regex provided by suresh.csk earlier in this thread. I added a capturing group that will capture the email domain. You can compare the value captured in group 2 against the email domain(s) you're trying to reject and abort your registration process.

 

Try the regex out here on this great regular expression test page: http://www.regexplanet.com/advanced/java/index.html. It will also do the escaping of \ characters for you. Just copy the "as a Java string" value and paste it into your Apex code.

Nikhil MoreNikhil More
Hey Thanks Buddy,

I tried rewriting the trigger I were putting on user object, it seems to be working as expected.
I will sure try this out as well because with the trigger I am unable to show an error to user registering as external chatter.
I believe validations as suggested here would perform better.
Thanks a lot!! Appreciate it..



Regards,
Nikhil.

[cid:image001.jpg@01CE2006.7CA5B410]

Nikhil More.
Programmer,
Java/ Salesforce.


________________________________
This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the e-mail by you is prohibited.

Where allowed by local law, electronic communications with Accenture and its affiliates, including e-mail and instant messaging (including content), may be scanned by our systems for the purposes of information security and assessment of internal compliance with Accenture policy.

______________________________________________________________________________________

www.accenture.com
TLFTLF

Yeah, I think you could do it with a validation rule as well. Modify the one suggested by suresh.csk, adding an OR clause that also rejects emails containing the undesired domains (using the CONTAINS function in your validation rule).

 

I think if you want to stop the insertion of the User record and display an error on the registration form, you can call the "addError" function on the User object being rejected by your trigger code. 

Nikhil MoreNikhil More
Hey Thanks,

I wrote a trigger for user before insert and used add error.
Now m facing some issues for sending mail which I have raised a case with Salesforce.
I will post you soon what they come up with.

Thanks,
Nikhil More.
Accenture.

________________________________
This message is for the designated recipient only and may contain privileged, proprietary, or otherwise confidential information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the e-mail by you is prohibited.

Where allowed by local law, electronic communications with Accenture and its affiliates, including e-mail and instant messaging (including content), may be scanned by our systems for the purposes of information security and assessment of internal compliance with Accenture policy.

______________________________________________________________________________________

www.accenture.com
mdnskmdnsk

Please explain email id validation rule with example. I didnt understand that particular format

 

Thanks,

mdnsk

TLFTLF

The example I posted is a regular expression that must be utilized using the Apex Pattern and Matcher classes. Here's an example showing the usage of this regular expression to validate whether a string is a valid email address. It also shows how you can use it to capture the email domain.

Pattern p = Pattern.compile( '([a-zA-Z0-9_\\-\\.]+)@(((\\[a-z]{1,3}\\.[a-z]{1,3}\\.[a-z]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3}))');
String[] emailAddressList = new String[]{'test@test.com', 'test1.test.com', 'test2@test.com', 'test-3@test.com', 'test4-test.com'};
for (String emailAddress : emailAddressList) {
	System.debug('Email address: ' + emailAddress);
	Matcher m = p.matcher(emailAddress);
	if (m.matches()) {
		System.debug('Valid email address. Email domain: ' + m.group(2));
	} else {
		System.debug('Invalid email address!');
	}
}

 Here is the debug output using the inputs in the example:

 

06:54:07.063 (63899000)|USER_DEBUG|[4]|DEBUG|Email address: test@test.com
06:54:07.067 (67111000)|USER_DEBUG|[7]|DEBUG|Valid email address. Email domain: test.com
06:54:07.067 (67192000)|USER_DEBUG|[4]|DEBUG|Email address: test1.test.com
06:54:07.067 (67427000)|USER_DEBUG|[9]|DEBUG|Invalid email address!
06:54:07.067 (67501000)|USER_DEBUG|[4]|DEBUG|Email address: test2@test.com
06:54:07.067 (67764000)|USER_DEBUG|[7]|DEBUG|Valid email address. Email domain: test.com
06:54:07.067 (67836000)|USER_DEBUG|[4]|DEBUG|Email address: test-3@test.com
06:54:07.068 (68098000)|USER_DEBUG|[7]|DEBUG|Valid email address. Email domain: test.com
06:54:07.068 (68176000)|USER_DEBUG|[4]|DEBUG|Email address: test4-test.com
06:54:07.068 (68384000)|USER_DEBUG|[9]|DEBUG|Invalid email address!

 

Sophia EdwardSophia Edward
You can use Javascript validation if its a VF page, else you can utilise 360 Verify the email App for verifying the email addresses, after or before insert of data. This App provides real time data and integrates well with salesforce.

Go to the link- https://appexchange.salesforce.com/listingDetail?listingId=a0N3000000DpPL8EAN

Or for further inquiry go to- support@360degreeapps.com
 
 
 
Naveed Iqbal 9Naveed Iqbal 9
Simply but may be weak
NOT(AND(CONTAINS( My_Lead_Email__c , ".com") , CONTAINS( My_Lead_Email__c , '@') ) )
Milke SandersMilke Sanders
This is a very slight modification to the regex provided by suresh.csk earlier in this thread. I added a capturing group that will capture the email domain. You can compare the value captured in group 2 against the email domain(s) buyyoutubviews.com (https://buyyoutubviews.com/) you're trying to reject and abort your registration process.
Jacqueline CascioJacqueline Cascio

A validation rule can contain a formula or expression that evaluates the data in one or more fields and returns a value of “True” or “False”. Validation rules also include an error message to display to the user when the rule returns a value of “True” due to an invalid value.
https://www.rapidfs.org/