Validate the length of a string.
Option | HTML attribute | Type | Description |
---|---|---|---|
max |
data-bv-stringlength-max or maxlength |
Number | The maximum length. It's dynamic option |
message |
data-bv-stringlength-message |
String | The error message |
min |
data-bv-stringlength-min |
Number | The minimum length. It's dynamic option |
At least one of min
and max
options is required.
In the following form, the Full name and Bio fields must be less than 50 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>
$(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: 200,
message: 'The bio must be less than 200 characters'
}
}
}
}
});
});
The following validators might be useful to you: