Solved: Add validations rules on a migration script

Edit: solved!

After playing a bit with the UI I noticed that you need to manually add the url patten
And this is the solution

    .validations([
      {
        regexp: {
          pattern:
            "^(ftp|http|https)://(w+:{0,1}w*@)?(S+)(:[0-9]+)?(/|/([w#!:.?+=&%@!-/]))?$",
        },
      },
    ])

Hey there!

I am creating a migration-001.js script to create versioning of my content model
I have a footer with links and I want to add a validation rule.

  // New footer content type.
  const footer = migration
    .createContentType("footer")
    .name("Footer")
    .description("Footer links")
  footer
    .createField("url")
    .type("Symbol")
    .required(true)
    .name("Url")
    .validations([{ regexp: "url" }])     <------------------------ this is not working
  footer.createField("name").type("Symbol").required(true).name("Name")

image

My problem is:
I couldn’t find on the documentation on how to add url validation rules

https://www.contentful.com/help/available-validations/

1 Like