uri validator
Validate an URL address
Options
Using with form field
Name | HTML attribute | Type | Description |
---|
allowLocal | data-fv-uri___allow-local | Boolean | Allow the private and local network IP. It is false , by default |
message | data-fv-uri___message | String | The error message |
protocol | data-fv-uri___protocol | String | The protocols, separated by a comma. By default, it is set to http, https, ftp |
allowEmptyProtocol | data-fv-uri___allow-empty-protocol | Boolean | Allow the URI without protocol. Default to false |
Using with ES6 module
import uri from 'formvalidation/dist/es6/validators/uri';
const result = uri().validate({
value: ...,
options: {
allowLocal: ...,
message: ...,
protocol: ...,
allowEmptyProtocol: ...,
},
});
Basic example
HTML5 Example
When the
Declarative plugin is used, the uri validator will be turned on automatically if the input uses HTML 5
type="url"
attribute.
ES6 Module Example
The following snippet shows how to use the uri validator with ES6 module:
import uri from 'formvalidation/dist/es6/validators/uri';
const res1 = uri().validate({
value: 'http://foo.com/blah_blah_(wikipedia)',
options: {
message: 'The input is not a valid URL',
},
});
const res2 = uri().validate({
value: 'http://foo.bar?q=Spaces should be encoded',
options: {
allowLocal: true,
message: 'The input is not a valid URL',
},
});
const res3 = uri().validate({
value: 'news://foo.com/blah_blah',
options: {
allowEmptyProtocol: true,
message: 'The input is not a valid URL',
},
});
See also