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
Christopher PickingChristopher Picking 

Restricting characters and removing space at the end of a field

I want to restrict the following characters ‘ “ , * % @ and if possible remove any extra spaces at the end of the field. I've found validation rules for allowing characters but none for just restricting, I don't really want to have to input every single charachter other than those listed above. (infact when I try to do that I get syntax errors). Any guidence would greatly be appreciated.
Best Answer chosen by Christopher Picking
Terence_ChiuTerence_Chiu
You can use this formula example to validate against usage of those special characters and checking if there are spaces at the end.
 
OR(
 CONTAINS( Text_Field__c , "'"),
CONTAINS( Text_Field__c , '"'),
CONTAINS( Text_Field__c , ","),
CONTAINS( Text_Field__c , "*"),
CONTAINS( Text_Field__c , "%"),
CONTAINS( Text_Field__c , "@"),
CONTAINS(RIGHT(Text_Field__c, 1), " ") 
)

 

All Answers

Terence_ChiuTerence_Chiu
You can use this formula example to validate against usage of those special characters and checking if there are spaces at the end.
 
OR(
 CONTAINS( Text_Field__c , "'"),
CONTAINS( Text_Field__c , '"'),
CONTAINS( Text_Field__c , ","),
CONTAINS( Text_Field__c , "*"),
CONTAINS( Text_Field__c , "%"),
CONTAINS( Text_Field__c , "@"),
CONTAINS(RIGHT(Text_Field__c, 1), " ") 
)

 
This was selected as the best answer
Miroslav SmukovMiroslav Smukov
You can use regular expression in your validation rule to do this as well:
 
!REGEX( YourField , "^[^\"',*%@]+$")
This is the part that contains your characters: \"',*%@
Note that " had to be escaped with backslash \ 


For removing the extra spaces I would write a trigger or workflow - something like this maybe: https://success.salesforce.com/answers?id=90630000000Co59AAC