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
Phuc Nguyen 18Phuc Nguyen 18 

Validation rule for text

Hello,
I could use some help on how to create a validation rule that forces users to fomat their text input
For example.  I need the user input to be like 
A.123456.D.54 OR A.789456.E.89
First letter needs to be an A followed by a . followed by 6 digits(numbers only) followed by a . followed by a D or E  then followed by a . and then followed by 2 digits(numbers only)
Can I do this in a validation rule? 
Thank you,
P
 
Best Answer chosen by Phuc Nguyen 18
CharuDuttCharuDutt
Hii Phuc Nguyen 
I've made some changes in the validation rule try now
AND( ISBLANK( Application_Source__c ) ,NOT(REGEX( Application_Source__c ,"[A]{1}.[0-9]{6}")),NOT(REGEX( Application_Source__c ,"[D]{1}.[0-9]{2}")),NOT(REGEX( Application_Source__c ,"[E]{1}.[0-9]{2}")))
Please Mark It As Best Answer If It Helps
Thank You!

 

All Answers

CharuDuttCharuDutt
Hii Phuc Nguyen
Try Below Validation Rule
AND(NOT(REGEX( Application_Source__c ,"[A]{1}.[0-9]{6}")),NOT(REGEX( Application_Source__c ,"[D]{1}.[0-9]{2}")),NOT(REGEX( Application_Source__c ,"[E]{1}.[0-9]{2}")))
Please Mark It As Best Answer If It Helps
Thank You!
Phuc Nguyen 18Phuc Nguyen 18
Thanks for the reply CharuDutt. its running even when the field is blank.  How do I get around that?
Phuc Nguyen 18Phuc Nguyen 18
Does not appear to be working.  Is there a way for me to troubleshoot the validation rule?
 
Phuc Nguyen 18Phuc Nguyen 18
CharuDutt are those 2 single quotes in the vlaidation?
CharuDuttCharuDutt
Hii Phuc Nguyen 
I've made some changes in the validation rule try now
AND( ISBLANK( Application_Source__c ) ,NOT(REGEX( Application_Source__c ,"[A]{1}.[0-9]{6}")),NOT(REGEX( Application_Source__c ,"[D]{1}.[0-9]{2}")),NOT(REGEX( Application_Source__c ,"[E]{1}.[0-9]{2}")))
Please Mark It As Best Answer If It Helps
Thank You!

 
This was selected as the best answer
Phuc Nguyen 18Phuc Nguyen 18
Hello CharuDutt,
Thank you for the reply.  Does your example work in your test org?  So no the user has to have a value in the field.  Which is not the case.  And it appears that the validation is not triggering correctly even when there is a value in the field.  Not sure why.  I think the formula looks correct.
Phuc Nguyen 18Phuc Nguyen 18
I think this did it. Thank you

AND( 
NOT(ISBLANK( Application_Source__c )),
NOT(REGEX( Application_Source__c ,"[A{1}.[0-9]{6}.[D]{1}.[0-9]{2}")),
NOT(REGEX( Application_Source__c ,"[A]{1}.[0-9]{6}.[E]{1}.[0-9]{2}"))
)