Validate an URL address.
Option | HTML attribute | Type | Description |
---|---|---|---|
allowLocal |
data-bv-uri-allowlocal |
Boolean | Allow the private and local network IP. It is false , by default. |
message |
data-bv-uri-message |
String | The error message |
You can use type="url"
attribute to enable this validator.
Thank to Mathias Bynens for providing this amazing collection of URL examples.
<form id="urlForm" class="form-horizontal">
<div class="form-group">
<label class="col-lg-3 control-label">Your website</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="website" />
</div>
</div>
</form>
$(document).ready(function() {
$('#urlForm').bootstrapValidator({
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
website: {
validators: {
uri: {
message: 'The website address is not valid'
}
}
}
}
});
});
The following form uses HTML 5 type="url"
attribute to enable the uri validator.
<form id="html5Form" class="form-horizontal">
<div class="form-group">
<label class="col-lg-3 control-label">Your website</label>
<div class="col-lg-6">
<input class="form-control" name="website"
type="url" data-bv-uri-message="The website address is not valid" />
</div>
</div>
</form>
$(document).ready(function() {
$('#html5Form').bootstrapValidator({
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
}
});
});
The following validators might be useful to you: