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
bayforcebayforce 

Email address validation function re-use

I've defined a custom object with an email address data type field. Is there a way to re-use the existing email validation that Salesforce implements? I'd like to do as much validation prior to inserting the record. I can implement my own but would rather re-use.
Edwin VijayEdwin Vijay

Do you mean verification of the email address, or is it just the validation to check whether it is just a email address..

 

If its just the validation, then i think it is already taken care of because the datatype is "email"

bayforcebayforce

I'm interested in validating the email address format (i.e., it contains an @, a domain, acceptable chars, probably more...).

 

// Client-side validation (in JS)

 

 

// Server-side validation

(in a controller that processes a form...)

// Validate email address submitted in form

// Check for required fields in the form

try {

// Insert record

} catch (DmlException e) {

// Handle exception

}

 

I'd like to push the email  validation up in the flow, so that I can handle it before a slightly more expensive DB exception. Is there an existing email address format validation function that I can use? I figured if the function that the DB 'email' datatype uses is exposed, then I could use that.

 

Aaron BaumanAaron Bauman

I would love to know the exact regular expression or other validation used for emails, since it's obviously different from the one I'm using (drupal).

 

Therefore an email address can pass validation on my website, but SF API won't let me save the record.

Ken_KoellnerKen_Koellner

I think it's critical to know what the format is yet the help info says it just validates and doesn't say what the format is.

 

The one thing I find majorly irksome about SF is the documentation is woefully inadequate with respect to any reasonable amount of detail.  I like working with SF but it's the most thinly document SW I've ever used.

White Knight AdminWhite Knight Admin
If the intent is to pass an form field from a Flow or via the Force.com API, validate the field with:
REGEX({!Email_Address},"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}")
Salesforce Reference: https://developer.salesforce.com/docs/atlas.en-us.salesforce_vpm_guide.meta/salesforce_vpm_guide/vpm_designer_elements_screen_val.htm