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
Integration User 617Integration User 617 

Regex validation rule for birthday

Hi all,

I am attempting to create a validation rule for a birthday field (US) where the user has the ability to enter either MM/DD or MM/DD/YYYY. While I have the validation currently working, my issue is that the REGEX currently allows for months greater than 12 which is causing issues for data governance. Is it possible to have either a LEFT(Birthday__c, 2) < 12 or modify the Regex so that it does not allow for months greater than 12? Below is a sample of my rule:

 
NOT( 
OR( 
ISBLANK(Birthday__c), 
REGEX(Birthday__c , "[0-1]{1}[0-9]{1}/[0-3]{1}[0-9]{1}"), 
REGEX(Birthday__c , "[0-1]{1}[0-9]{1}/[0-3]{1}[0-9]{1}/[1-2]{1}[0-9]{1}[0-9]{1}[0-9]{1}") 
) 
)

 
Best Answer chosen by Integration User 617
Ramesh DRamesh D
Hi,
Please try below Regex and let me know if it works
NOT( 
OR( 
ISBLANK(Birthday__c), 
REGEX(Birthday__c , "(0?[1-9]|1[0-2])/(0?[1-9]|1[0-9]|2[0-9]|3[01])"), 
REGEX(Birthday__c , "(0?[1-9]|1[0-2])/(0?[1-9]|1[0-9]|2[0-9]|3[01])/\\d{4}") 
) 
)

I hope you find the above solution helpful. If it does mark as best answer to help others too.
Thanks,
Ramesh D