Email Format Check

  • 1
  • Question
  • Updated 2 years ago
  • Answered
I currently use the following in salesforce to check if the user put in a valid email format:

IF( Text(Temp_Type__c)  = "New Member", IF(REGEX ( UPPER (  Temp_Lead_Email__c  ) ,"^[A-Z0-9._%+-/!#$%&'*=?^_`{|}~]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$") = TRUE, FALSE, 
TRUE),FALSE)

I would like to do this within skuid before being sent to sales force.  Is there some code that could be put in a UI-field or some script that can check for proper formating?
Photo of Bill Fox

Bill Fox

  • 7,954 Points 5k badge 2x thumb

Posted 2 years ago

  • 1
Photo of Barry Schnell

Barry Schnell, Champion

  • 18,086 Points 10k badge 2x thumb
Hi Bill -

This would be another scenario where having the ability to write a custom formula function would make things extremely easy. If you could write a custom formula function, you could write one called "ISVALIDEMAIL" that would apply a regular expression to a value and determine if its valid. From there, you could add a UI Only Field that applied that function and conditionally render your "save" button based on the UI Only field. Vote up custom formula functions here https://community.skuid.com/skuid/top....

In the absence of custom formula functions, you're solutions become a little more difficult but it is still possible:

1) Set your save button to "Run Multiple Actions" and in one of the steps in the action sequence before "Save" run a snippet. In the snippet, use a regular expression to validate the email address field and return false if not valid, true if valid. This, in essense, becomes a custom form of validate Fields similar to the stock functionality of validateRequiredFields.

2) Add a UI Only Field called "Valid Email". Add a snippet called "validateEmail" that runs the regex against the email field and updates the UI Only field. Setup a model change action for the email field to run the snippet anytime the email field changes. Conditionally render/enable the save button based on the UI Only FIeld

3) Write a custom renderer for the Email field and apply the validation as the data is changing or find a third-party javascript library that will do this for you.

One thing to note - Validating email addresses using regular expressions is a very difficult task if you validate using the true RFC spec. The regular expression you are using in your SFDC formula field covers "most" scenarios but not all. Just a word of caution depending on what your business requirements are. I'll leave it to you to determine but you can use your favorite search engine to search for more information about using regexs to validate email addresses :)
Photo of Bill Fox

Bill Fox

  • 7,954 Points 5k badge 2x thumb
I get it.  Thanks Barry.