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
Arash TeimoupoorArash Teimoupoor 

validation rule to exclude special characters except (.) and (‘).

Hi Everyone,

I want to have a validation rule to prevent special characters in text field except these 2: (.) and (‘).  please advise. thanks
Cyrus TalladenCyrus Talladen
I would try a regular expression.  For example
 
NOT(REGEX(My_Field__c, "{.}{'}")

Cyrus T
www.levementum.com
 
Arash TeimoupoorArash Teimoupoor
Thanks for your reply. I used thhis 

NOT(REGEX( test__c ,"{.}{'}"))

and I received this error when I tried to save it:
Error: java.util.regex.PatternSyntaxException: Illegal repetition {.}{'}
Cyrus TalladenCyrus Talladen
Depending on what you want you can test your expressions at

https://regex101.com/

Im not sure if you want substrings containing . or ' or multiple occurrences
 
 
Arash TeimoupoorArash Teimoupoor
I just want to prevent any special character except for . and '
Cyrus TalladenCyrus Talladen
Try this:
 
NOT(REGEX( test__c ,"[^.']"))
 
 
Arash TeimoupoorArash Teimoupoor
When I use this, the text field does not accept anything, not even normal text
David ZhuDavid Zhu
This works for me.

not(REGEX( Company , "[a-zA-Z0-9\\.\\']+"))


 
Arash TeimoupoorArash Teimoupoor
David,
I guess that works too. this is what I used and is working well.( almost same as yours)

NOT( REGEX( test__c , "[a-zA-Z0-9.']+"))

Thanks for your reply
SFadmin SFadmin 4SFadmin SFadmin 4
This formula first checks to make sure the field isn't blank and then evaluates the characters within. Specifically, I'm trying to omit < > & ' " from my address field. You can alter the characters as needed or change this from a "NOT" expression

AND( 
(NOT (ISBLANK(BillingStreet ))), 
(NOT(REGEX(BillingStreet , "^[^<>&\"\']*$"))) 
)

(1) You need to escape single and double quotes with a proceeding backslash (eg \" or \') so that salesforce understands you're trying to use the literal values
(2) you need a ^ symbol before and after your start bracket ...this wouldn't necessarily be the case if using the regular expression anywhere other than SFDC
(3) you need *$ after your end bracket ...this also wouldn't necessarily be the case if using the regular expression anywhere other than SFDC
...2 and 3 above imply "starts with" and "ends with" but SFDC evaluates this to "contains". So, this validation rule catches 123 Main St Suite A&B ...as intended... but allows 123 Main St Suite A and B ...also as intended.
jordangroodyjordangroody
Extremely helpful. I stole and added my own characters related to preventing issues creating files in sharepoint.for SF Opportunities. (Don;t ask, it's a crazy org. 

Name = Opportunity Name
NOT(REGEX(Name , "^[^<:>*?|.&\"\']*$"))