URL

A string which represents a URL.

Properties

  • REQUIREDtypestring

    Value must be set to url.

Validation

Learn more about validation
  • uri(options)function

    scheme - String, RegExp or Array of schemes to allow (default: ['http', 'https']).

    allowRelative - Whether or not to allow relative URLs (default: false).

    relativeOnly - Whether to only allow relative URLs (default: false).

  • custom(fn)function

    Creates a custom validation rule.

The URL type is basically just a string input, but the rendered HTML input field will have the type attribute set to url, like so:

<input type="url">

Input

{
  title: 'Image URL',
  name: 'imageUrl',
  type: 'url'
}

Output

{"imageUrl": "https://example.com/img.jpg"}

To allow more protocols than http/https, you can specify validation options:

{
  title: 'Link',
  name: 'href',
  type: 'url',
  validation: Rule => Rule.uri({
    scheme: ['http', 'https', 'mailto', 'tel']
  })
}

Was this article helpful?