0

I'm basically having validation rule in salesforce to check the whether entered value is in required format or not. However in below formula validation formula for Pan Number is working fine but for Aadhaar Number getting error.

IF(
ISPICKVAL(Proof_id_type__c,"Pan number"),
(LEN(Proof_Id_number__c) != 10) && NOT( REGEX( Proof_Id_number__c , "[A-Za-z]{5}[0-9]{4}[A-z]{1}") ),True
) || 
IF(
ISPICKVAL(Proof_id_type__c,"Aadhar number"),
(LEN(Proof_Id_number__c) != 12) && NOT( REGEX( Proof_Id_number__c , "[0-9]{12}") ) ,True
)

How to solve this if you could help on this.

1
  • 1
    Welcome to SFSE. Please take a moment to read How to Ask and take the tour. Commented Aug 11, 2022 at 15:12

1 Answer 1

1

The Regex Expressions were correct which you have shared in the question but some issues in the implementation .

For Pan Card the Validation should be as below. I Just Removed the If() Clause and added AND() and OR() conditions to it. I have added OR() clause in for length and Regex because if any condition fails the validation should fire

AND(ISPICKVAL(Proof_Id_Type__c,"Pan number"), OR((LEN(Proof_Id_Number__c) != 10) , NOT( REGEX( Proof_Id_Number__c , "[A-Za-z]{5}[0-9]{4}[A-z]{1}") )))

For Aadhar Card the validation will be as below.

AND(
ISPICKVAL(Proof_Id_Type__c,"Aadhar number"), OR(LEN( Proof_Id_Number__c )<>12 , NOT(REGEX(Proof_Id_Number__c, "[0-9]{12}"))
))

Now the validation needs to be combined and need to work for both Aadhar and Pancard so use OR() condition for both as below.

or(AND(
ISPICKVAL(Proof_Id_Type__c,"Aadhar number"), OR(LEN( Proof_Id_Number__c )<>12 , NOT(REGEX(Proof_Id_Number__c, "[0-9]{12}"))
)),

AND(ISPICKVAL(Proof_Id_Type__c,"Pan number"), OR((LEN(Proof_Id_Number__c) != 10) , NOT( REGEX( Proof_Id_Number__c , "[A-Za-z]{5}[0-9]{4}[A-z]{1}") ))))
2
  • Thank you @SaiPraveen Kakkirala it worked. Commented Aug 11, 2022 at 9:23
  • If the answer helped/worked, please consider accepting the answer (and upvoting it). It's how we provide thanks on the site. Commented Aug 24, 2022 at 13:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .