Skip to content

url ​

The string is a URL with an allowed protocol. Only http and https by default.

Signature ​

ts
function url(msg?: Message, protocols?: string[]): Action<string>

Parameters ​

ParameterTypeDescription
msgMessageCustom error message
protocolsstring[]Allowed protocols. Default ['http', 'https']

Error codes ​

CodeWhenDefault message
urlNot a URL or another protocolInvalid URL

You can change the texts: see Messages & i18n.

Notes ​

javascript: and data: links won't pass — the value is safe to put into href. A domain without a protocol (example.com) is an error too: add the protocol with preprocess or check with startsWith.

Example ​

ts
const Profile = object({
  website: optional(pipe(string(), trim(), url())),
  ftp: optional(pipe(string(), url(undefined, ['ftp', 'sftp']))),
});

See also ​