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
DJ 367DJ 367 

REGEX Code is not working

Hello All,

I am validating on field as format ,any numeric and alpha numeric(4) then (-) again any numeric and alpha numeric(5)
Eg. AA12-A322R
 
NOT(REGEX(CurrentGenerators__c,"[a-zA-Z0-9]{4}[-][a-zA-Z0-9]{5}"))
Regards,
Dinesh
Best Answer chosen by DJ 367
Alain CabonAlain Cabon
Hi,

The underlying regex engine of Salesforce is based on java.
  • $ : Matches the end of the input. If in multiline mode, it also matches before a line break character, hence every end of line.
  • ^ : Matches the beginning of the input.
 
NOT(REGEX(CurrentGenerators__c,"^[a-zA-Z0-9]{4}[-][a-zA-Z0-9]{5}$"))

You can made tests with this online tool: https://www.freeformatter.com/java-regex-tester.html
 

All Answers

Balu_SFDCBalu_SFDC
try something like this

NOT(REGEX(CurrentGenerators__c,"^[a-zA-Z0-9]{4}\\-\\^[a-zA-Z0-9]{5}"))
DJ 367DJ 367
Hi,
It is not working.
Alain CabonAlain Cabon
Hi,

The underlying regex engine of Salesforce is based on java.
  • $ : Matches the end of the input. If in multiline mode, it also matches before a line break character, hence every end of line.
  • ^ : Matches the beginning of the input.
 
NOT(REGEX(CurrentGenerators__c,"^[a-zA-Z0-9]{4}[-][a-zA-Z0-9]{5}$"))

You can made tests with this online tool: https://www.freeformatter.com/java-regex-tester.html
 
This was selected as the best answer