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
Jim Riggio 1Jim Riggio 1 

regex validation rule for special characters and length 24

Hello , i am trying to create a validation rule using REGEX, but can't seem to get it the correct way.  I assume I am not using the function correctly.
I need to make sure the first two characters are AB or ab and the entire length of the string is 24 characters. I was successful in targeting the first two characters, but can't seem to determine the length. The remaining 22 characters can be any alphanumeric character including special characters.  I don't know if I can do this with REGEX.  I tried to use the combinations of BEGINS and LEN functions, but can't seem to get to work.

This is where I ended up with (but doesn't work)
NOT(REGEX(Test_ID__c, "^([Aa]?[Bb])+{22}$"))
Best Answer chosen by Jim Riggio 1
William TranWilliam Tran
This should do the trick:
 
NOT(REGEX(testtext__c, "^([Aa]?[Bb]).{22}$"))

As a common practice, if your question is answered, please choose 1 best answer. 
But you can give every answer a thumb up if that answer is helpful to you. 

Thanks

All Answers

William TranWilliam Tran
This should do the trick:
 
NOT(REGEX(testtext__c, "^([Aa]?[Bb]).{22}$"))

As a common practice, if your question is answered, please choose 1 best answer. 
But you can give every answer a thumb up if that answer is helpful to you. 

Thanks
This was selected as the best answer
Jim Riggio 1Jim Riggio 1
Works great..thanks so much ( i almost had it)
Sonya Dhand 14Sonya Dhand 14
Hi I am using the following to validate an text field has email addresses entered in the correct format.  However I also need to ensure between each email address there is a ; seperator  

The regex I found onlne is  NOT( REGEX(Custom_email_list__c , "([A-Za-z0-9]+([!#$%&'*+-/=?^_`{|}~]*[A-Za-z0-9]+)*@[A-Za-z0-9\\-]+(\\.[A-Za-z0-9\\-]+)*[ ]*[,;]?[ ]*)+" )) which works well but still works without a ; between email addresses

How do I ensure ; is present and if not it will throw the validation error?
Many thanks in advance