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
llisallisa 

Validation Rule using Regular Expression

Hello Everyone,

i am trying to make a validation rule for a text field with 2 decimal values just like 20/30,40/50,1/2,12/4 and single numbers.
It should give error message if it is like 122/22 or 299/349.

Here i wrote a validation rule :
NOT(REGEX(Edited_Discount__c,"[0-9]+[/]{1}[0-9]{2}"))

It will Validate 20/30,40/50 but when i give single it throws validation exception.
Please help me on this .

Thanks
Lisa
Nayana KNayana K
Try this once :
NOT(REGEX(Edited_Discount__c,"[0-9]+[/]{1}[0-9]{1,2}"))

OR

NOT(REGEX(Edited_Discount__c,"[0-9]{1,2}[/]{1}[0-9]{1,2}"))
RudrarajuRudraraju
Hi Lisa,

Try this one. It worked for me
Not(REGEX( AccountNumber, "[0-9]{1,2}[/]{1}[0-9]{1,2}"))
llisallisa
Hi Surya and Nayaka. Thanks a lot for your reply and sorry for late reply. The code you provided works fine but not for single number . When i give 10,30,50 it throws me error. So if you know. kindly help on this .
Nayana KNayana K
NOT(REGEX(Edited_Discount__c,"[0-9]{1,2}[/]{0,1}[0-9]{0,2}"))

Try this once
llisallisa
Hi,

I wrote a validation rule :
AND (LEN(Edited_Discount__c) <> 2 , LEN(Edited_Discount__c) <> 1 ,NOT(REGEX(Edited_Discount__c,"[0-9]{1,2}[/]{1}[0-9]{1,2}")))

It works. If you know anything else then this . plz share your ideas with me.

Thanks
Lisa
RudrarajuRudraraju
Try this Once

AND(Not(REGEX( AccountNumber, "[0-9]{1,2}[/]{1}[0-9]{1,2}")), NOT(REGEX( AccountNumber, "[0-9]{1,2}")))