v0.5.3 is released on 2014.11.05!
Options
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 |
protocol |
data-bv-uri-protocol |
String | The protocols, separated by a comma. By default, it is set to http, https, ftp |
When setting options via HTML attributes, remember to enable the validator by setting data-bv-uri="true".
You don't need to do that when using HTML 5 type="url" attribute.
You don't need to do that when using HTML 5 type="url" attribute.
Examples
Basic example
Thank to Mathias Bynens for providing this amazing collection of URL examples.
<form id="uriForm" class="form-horizontal">
<div class="form-group">
<label class="col-sm-3 control-label">Your website</label>
<div class="col-sm-6">
<input type="text" class="form-control" name="website" />
</div>
</div>
</form>
$(document).ready(function() {
$('#uriForm').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'
}
}
}
}
});
});
HTML 5 example
The following form uses HTML 5 type="url"
attribute to enable the uri validator.
<form id="uriHtml5Form" class="form-horizontal">
<div class="form-group">
<label class="col-sm-3 control-label">Your website</label>
<div class="col-sm-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() {
$('#uriHtml5Form').bootstrapValidator({
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
}
});
});
Related validators
The following validators might be useful to you: