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
pradeep prakashpradeep prakash 

Syntax Error using regex in salesforce validation rule

NOT(
OR(
ISBLANK(DOS_ID__c),
REGEX(DOS_ID__c,"^([CT]{2}[0-9]{8}\s?)+([,]\s?([CT]{2}[0-9]{8}\s?)+)*$")
)
)

I get syntax error using this. please help.

Requirement: in a custom field the value entered should be CT***********, CT***********, etc or CT*********

CT followed by 8 digits. it can be single entry or comma seperated repeated entry.
 
Rupal KumarRupal Kumar
hi pradeep,

Try this 
NOT( 
AND( 
OR( 
LEN (zip__c) = 0, 
REGEX(DOS_ID__c,"([A-Z]{2}[0-9]{8})+([,][A-Z]{2}[0-9]{8})") 
), 
BEGINS(DOS_ID__c,"CT") 
))

Thanks
Rupal.
Mirketa Pvt Ltd.
pradeep prakashpradeep prakash
NOT(
OR(
ISBLANK(DOS_ID__c),
REGEX(DOS_ID__c,"^([Cc]{1}[Tt]{1}[a-zA-Z]{1}([0-9]){7})+([\\s]*[,]+[\\s]*[Cc]{1}[Tt]{1}[a-zA-Z]{1}([0-9]){7})*$")
)
)

This worked for me