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
mrhmrh 

REGEX syntax help

Hello all

 

I am trying to include a REGEX in a field validation rule to check that for a given field of length 8 chars, the value entered has the following syntax:

 

1st char:  X

2nd char: any alpha numeric

3rd char: any alpha numeric

4th char: any alpha numeric

5th char: any alpha numeric

6th char: 0

7th char: 1

8th char: any alpha numeric

 

I have tried the following but its not quite there.  Could anyone please suggest a solution?

 

NOT(REGEX(field__c, "(X\\[a-zA-Z0-9]{5}\\01\\[a-zA-Z0-9]{1})"))

 

Many thanks in advance.

Best Answer chosen by Admin (Salesforce Developers) 
liron169liron169

try

 

NOT(REGEX(field__c, "(X[a-zA-Z0-9]{4}01[a-zA-Z0-9]{1})"))

 

 

All Answers

liron169liron169

try

 

NOT(REGEX(field__c, "(X[a-zA-Z0-9]{4}01[a-zA-Z0-9]{1})"))

 

 

This was selected as the best answer
mrhmrh

Great, thanks very much for your help.

 

Best regards,
mark

liron169liron169
No problem.

By the way I think you'll achieve the same result with:

(X\w{4}01\w{1})

since \w search for alphanumeric char
mrhmrh

Thanks again.

 

Would it also be possible to include something similar when displaying the same field as as an outputText field on a display page?

 

i.e. for the 'rendered' attribute for the output text field, could I do something to re-use the regex again to only display the fields which have been actually completed, i.e. not the default value or blank.  I've tried to do something for this using the trim function but haven't been successful. e.g.

 

<apex:outputText rendered="{!ISBLANK(field.Id) && TRIM(field) != 'X 01'}"value=" "/>