Validate the length of a string.
Option | Equivalent HTML attribute | Type | Description |
---|---|---|---|
message |
data-bv-stringlength-message |
String | The error message |
min |
data-bv-stringlength-min |
Number | The minimum length |
max |
data-bv-stringlength-max or maxlength |
Number | The maximum length |
At least one of min
and max
options is required.
In the following form, the Full name and Bio fields must be less than 80 and 200 characters respectively.
<form id="profileForm" class="form-horizontal">
<div class="form-group">
<label class="col-lg-3 control-label">Full name</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="fullName" />
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Bio</label>
<div class="col-lg-6">
<textarea rows="5" class="form-control" name="bio"></textarea>
</div>
</div>
</form>
<script>
$(document).ready(function() {
$('#profileForm').bootstrapValidator({
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
fullName: {
validators: {
stringLength: {
max: 50,
message: 'The full name must be less than 50 characters'
}
}
},
bio: {
validators: {
stringLength: {
max: 250,
message: 'The bio must be less than 200 characters'
}
}
}
}
});
});
</script>
Comments
If you want to report a bug, please submit the issue on Github. Do NOT post the issue here.
For a general question or feedback, use the form below.