URL modifier
A modifier which creates a validation rule to ensure that a given string is a valid URL.
Schemas
string: Learn more
Arguments
message?- A custom object with error messages to be displayed when validation fails or there are type errors
Example
import { url, string } from '@nordic-ui/validathor';
const urlRule = string([
url({
type_error: "Must be a valid URL",
}),
]);
try {
const parsedValue = urlRule.parse('https://example.com');
console.log('Parsed value:', parsedValue);
} catch (error) {
console.error('Parsing failed:', error.message);
}Valid URL Formats
The URL modifier uses the built-in JavaScript URL constructor for validation, which accepts:
https://example.comhttp://example.comftp://files.example.comhttps://example.com:8080https://subdomain.example.comhttps://example.com/path/to/resourcehttps://example.com?query=valuehttps://example.com#anchorhttps://user:pass@example.com