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
mwremedymwremedy 

HELP! Complex Validation! Challenge!

Hello,

 

I am a VERY new salesforce user, and unfortunately am likely trying to tackle too much, but basically, I have a custom field that I want to add a validation rule for.  I have a 9 digit alphanumeric field that has a very specific set of validations I need performed.  I would GREATLY appreciate the help.

 

The number is 2 letters, 6 numbers, and 1 checksum digits. The 2nd letter is the initial of the contacts last name and the 7th is calculated as: add 1st, 3rd, and 5th digits, then add 2nd, 4th, and 6th digits and multiply by 2.  Add those 2 numbers together. The last digit of this last sum shold be the 7th digit.

 

I know this is likely crazy, but I would like to verify the following:

1. The field is exactly 9 digits, and the first two are letters, and the last 7 are numbers.

2. The 2nd letter matches the first letter of the contacts last name

3. the 7th digit is equal to last digit (ie. RIGHT(x,1) of ( (1st+3rd+5th) + ((2nd+4th+6th)*2) ). 

 

THANK YOU VERY MUCH FOR YOUR HELP!! 

JakesterJakester
Couple of thoughts here. First, it would be very helpful to know where this custom field is. Is it on the Contact object? Account object? Unless the field has a direct relationship with the Contact record, it will be hard to validate against the contact's name. Second, just curious, why are you making your users type this complex value? If it always has to be in the exact context you've specified, why not just make a formula that calculates it for the user, rather than make the user figure it out, and prevent them from saving until they get it right? Finally, if you have some good reason for running these checks, you'll want to look into RegEx() for the specific length and allow text vs numbers, and using Right() and Left() for the rest.
MSheridanMSheridan
Are you trying to do a luhn algorithm?