| 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
|
// You might need to change the importing path
import
uri
from
'formvalidation/dist/es6/validators/uri'
;
const
result
=
uri
(
)
.
validate
(
{
value
:
...
,
options
:
{
allowLocal
:
...
,
message
:
...
,
protocol
:
...
,
allowEmptyProtocol
:
...
,
}
,
}
)
;
/*
result is an object of
{
valid: true or false,
message: The error message
}
*/
type="url"
attribute.
// You might need to change the importing path
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'
,
}
,
}
)
;
// res1.valid === true
const
res2
=
uri
(
)
.
validate
(
{
value
:
'http://foo.bar?q=Spaces should be encoded'
,
options
:
{
allowLocal
:
true
,
message
:
'The input is not a valid URL'
,
}
,
}
)
;
// res2.valid === false
const
res3
=
uri
(
)
.
validate
(
{
value
:
'news://foo.com/blah_blah'
,
options
:
{
allowEmptyProtocol
:
true
,
message
:
'The input is not a valid URL'
,
}
,
}
)
;
// res3.valid === true