You need to sign in to do that
Don't have an account?

Regex Validation help to ensure ; separates multiple email addresses in a long text field?
Hi
I am using the following to validate an text field has email addresses entered in the correct format. However I also need to ensure between each email address there is a ; seperator
The regex I found onlne is :
NOT( REGEX(Custom_email_list__c , "([A-Za-z0-9]+([!#$%&'*+-/=?^_`{|}~]*[A-Za-z0-9]+)*@[A-Za-z0-9\\-]+(\\.[A-Za-z0-9\\-]+)*[ ]*[,;]?[ ]*)+" ))
which works well but still works without a ; between email addresses
How do I ensure ; is present and if not it will throw the validation error?
Many thanks in advance
I am using the following to validate an text field has email addresses entered in the correct format. However I also need to ensure between each email address there is a ; seperator
The regex I found onlne is :
NOT( REGEX(Custom_email_list__c , "([A-Za-z0-9]+([!#$%&'*+-/=?^_`{|}~]*[A-Za-z0-9]+)*@[A-Za-z0-9\\-]+(\\.[A-Za-z0-9\\-]+)*[ ]*[,;]?[ ]*)+" ))
which works well but still works without a ; between email addresses
How do I ensure ; is present and if not it will throw the validation error?
Many thanks in advance
May I request you please check with below links from the community forums which will point you in the right direction.
- https://success.salesforce.com/answers?id=90630000000CfI8AAK
- https://developer.salesforce.com/forums/?id=906F0000000AoNuIAK
- https://stackoverflow.com/questions/9809357/regex-for-validating-multiple-e-mail-addresses
Hope this helps.Please mark this as solved if it's resolved.
Thanks,
Nagendra
You can try this new regexp: Expression for validation of one or more emails separated by semicolon(;)
NOT( REGEX(substitute(trim(Custom_email_list__c ),' ',''), "^([a-z0-9,!#\\$%&'\\*\\+/=\\?\\^_`\\{\\|}~-]+(\\.[a-z0-9,!#\\$%&'\\*\\+/=\\?\\^_`\\{\\|}~-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\\.([a-z]{2,})){1}(;[a-z0-9,!#\\$%&'\\*\\+/=\\?\\^_`\\{\\|}~-]+(\\.[a-z0-9,!#\\$%&'\\*\\+/=\\?\\^_`\\{\\|}~-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\\.([a-z]{2,}))*$" ))
http://http://regexlib.com/REDetails.aspx?regexp_id=3013
A complete validation for only one email address is very complex in apex:
https://developer.salesforce.com/forums/?id=906F0000000BMjkIAG
Your expression allows also the commas and it is very difficult to validate this kind of regular expression for email (that seems to work but if it is too restrictive you will have a lot of rejects and that will be disastrous in production.
Best regards
Alain
(bad copy past above)
Your feedback about real tests of this complex regular expression would be interesting here.
The separator of the emails can be only the semicolon for this regular expression.
The separator is easy to find (there is only one semicolon in the regexp) for changing it but you have to choose only one separator ideally otherwise you could have :
email1@test.com ; email2@test.com , email3@test.com (mix of semicolon and comma).
By the way, if a response helped you, you can choose it and close your question (best practice here).
Best regards
Alain
<lightning:input type="email" label="Email"
pattern=".+@.+.com"
placeholder="username@yourDomain.com" />
</lightning:card>
MARK MY ANSWER AS BEST IF ITS HELP YOU