Validators / between

Edit on Github

Check if the input value is between (strictly or not) two given numbers.

Option Equivalent HTML attribute Type Description
message data-bv-between-message String The error message
min (*) data-bv-between-min or min Float The lower value in the range
max (*) data-bv-between-max or max Float The upper value in the range
inclusive data-bv-between-inclusive Boolean Can be true or false. If true, the input value must be in the range strictly

If you use min and max attributes, please set type="range".

Example

The following example validates latitude and longitude values.

A valid latitude must be between -90.0 and 90.0, and valid longitude may range from -180.0 to 180.0.

<form id="latlongForm" class="form-horizontal">
    <div class="form-group">
        <label class="col-lg-3 control-label">Latitude</label>
        <div class="col-lg-5">
            <input type="text" class="form-control" name="latitude" />
        </div>
    </div>

    <div class="form-group">
        <label class="col-lg-3 control-label">Longitude</label>
        <div class="col-lg-5">
            <input type="text" class="form-control" name="longitude" />
        </div>
    </div>
</form>
<script>
$(document).ready(function() {
    $('#latlongForm').bootstrapValidator({
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            latitude: {
                validators: {
                    between: {
                        min: -90,
                        max: 90,
                        message: 'The latitude must be between -90.0 and 90.0'
                    }
                }
            },
            longitude: {
                validators: {
                    between: {
                        min: -180,
                        max: 180,
                        message: 'The longitude must be between -180.0 and 180.0'
                    }
                }
            }
        }
    });
});
</script>
<form id="latlongForm" class="form-horizontal">
    <div class="form-group">
        <label class="col-lg-3 control-label">Latitude</label>
        <div class="col-lg-5">
            <input class="form-control" name="latitude"
                type="range" min="-90" max="90"
                data-bv-between-message="The latitude must be between -90.0 and 90.0" />
        </div>
    </div>

    <div class="form-group">
        <label class="col-lg-3 control-label">Longitude</label>
        <div class="col-lg-5">
            <input class="form-control" name="longitude"
                type="range" min="-180" max="180"
                data-bv-between-message="The longitude must be between -180.0 and 180.0" />
        </div>
    </div>
</form>
                
<script>
$(document).ready(function() {
    $('#latlongForm').bootstrapValidator({
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        }
    });
});
</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.