[SalesForce] Regex in the validation rule

There is a field for 6 digit serial number in a record. Since the field can contain only numbers, I have created a validation rule with regex to check only numbers are entered in the text field. But then the users needed the functionality to enter multiple serial numbers separated by semi-colon in a record. I've changed the VR to check for numbers and semi-colons.

 NOT(REGEX( Serial_Number__c ,  '^[0-6;]*$'))

But in addition, I'm trying change the VR to make sure that the user is entering only single or multiple 6 digit numbers separated by semi-colons. For example, 123456;234567;345678 and not 123;123456;45;5678

But it is not working.

 NOT(REGEX( Serial_Number__c ,  '^[0-6;]+\\d6*$'))

It is checking if there are only numbers and semi-colons but not if only six digit numbers are separated by semi-colons. Where is the mistake? Any help would be appreciated.

Best Answer

Try this RegEx [0-9]{6}(;[0-9]{6})*

Related Topic