Skip to content

Home > @opengovsg/validators > UrlValidator > (constructor)

UrlValidator.(constructor) ​

Creates a new UrlValidator instance. If no options are provided, the validator will use the default options:

ts
{
   whitelist: {
     protocols: ['http', 'https'],
   },
}

In most cases, you should provide your own whitelist with a list of allowed hostnames to prevent open redirects.

Signature:

typescript
constructor(options?: UrlValidatorOptions);

Parameters ​

ParameterTypeDescription
optionsUrlValidatorOptions(Optional) The options to use for validation

Exceptions ​

OptionsError If the options are invalid