Home
Support Forums

CMS Pattern not matching?

Using the code below I am trying to set the maximum length of a meta description box to be 300.
No matter what I type into the box, it will also say it did not match the pattern.
I have tried quite a few different regex patterns and also made sure I wasn’t using new lines just incase the . didn’t match all etc.

    fields:
              - {
                  label: Description,
                  name: description,
                  widget: text,
                  required: false,
                  pattern: [".{,300}", "Must not exceed 300 characters"],
                }

image

Hi @AaronP :wave:
You can test your pattern using a service like https://regex101.com/

For this specific case .{0,300} should work.

I was using regex tester and I also tried your Reged stated above. Just to confirm, if the pattern does NOT match then the error should show?

Yes, the error will show if the pattern doesn’t match.
To be more precise the pattern should be pattern: ['^.{0,300}$', 'Must not exceed 300 characters']
I’ve tested this locally:

If that still doesn’t work, can you share a repo reproducing the issue?

1 Like

Currently out but will update when I can. I haven’t tried including the ^ so maybe that’s the solution.

Marked as solution. The ^ and $ seemed to solve the issue! Thanks

1 Like