+ Start a Discussion
GMASJGMASJ 

Accept only specified special symbols

Hi, 
  
   We have a email field which should accept only @ . - as a special symbols if any other special symbols are entered it must not allow please suggest me how to add this valdiation 

Thanks
Sudhir
Best Answer chosen by GMASJ
Arpit Jain7Arpit Jain7
Hi Sudhir,

Please try below in your validation rule

NOT(REGEX ( UPPER ( Email_Domain__c ) ,"^[A-Z0-9.-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$"))

Let me know for any issues.

Thanks
Arpit

Please mark this answer as SOLVED and BEST ANSWER if it helps you.

All Answers

srlawr uksrlawr uk
Have you considered using an e-mail field type? That applies standard e-mail address format validation that will only allow those permitted characters in it:

User-added image
GMASJGMASJ
Thanks for your reply actuall field name is email domain which is a text field.  

I am currently using this belwo valdiation  which is working good will not expect any specical character 
NOT(REGEX(Email_Domain__c, "[a-zA-Z0-9.']+")) && ISCHANGED(Email_Domain__c)

 Now we have a requirement to allow few special character like @ . -  Only these special characters should be allowed. 


 Please suggest me. 


Thanks
Sudhir


 
Arpit Jain7Arpit Jain7
Hey Sudhir,

You can try below rule

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

For more details you refer below link for the same

https://help.salesforce.com/articleView?id=000170904&language=en_US&type=1

Let me know for any issues.

Thanks
Arpit

Please mark this answer as SOLVED and BEST ANSWER if it helps you.
GMASJGMASJ
Thanks Arpit for your reply. for some reason it is not working

Example : When i include ##@gmail.com it is accepting It must accept only if it has - . @ symbols  if any other symbols are enterd it must not accept. 

I Modified little adding ISCHANGED to the code. 
REGEX ( UPPER ( Email_Domain__c ) ,"^[A-Z0-9._%+-/!#$%&'*=?^_`{|}~]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$") && 
ISCHANGED(Email_Domain__c)
 Please suggest to fix this issue. 

Thanks
Sudhir




 
Arpit Jain7Arpit Jain7
Hi Sudhir,

Please try below in your validation rule

NOT(REGEX ( UPPER ( Email_Domain__c ) ,"^[A-Z0-9.-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$"))

Let me know for any issues.

Thanks
Arpit

Please mark this answer as SOLVED and BEST ANSWER if it helps you.
This was selected as the best answer
GMASJGMASJ
Hi Arpit, 

   It is not working tried your formula Please suggest

Thanks
Sudhir
Arpit Jain7Arpit Jain7
In what scenerio it is not working now ?
GMASJGMASJ
Even if no special character is entered it is not allowing It must just accept these special character . @ - other than any special character is entered it must not allow Please try once. 

Thanks
Sudhir
Arpit Jain7Arpit Jain7
Can you share some example where it should aloow you to save record but giving exception. I tried with some basic email addresses and it seems to be working.
GMASJGMASJ
Hi Arpit, 

  Appologies it is working I didn;t test properly.

Thanks
Sudhir
Arpit Jain7Arpit Jain7
That's good !! :) Please select best answer to close this thread also that would help other with same query

Thanks
Arpit