FormValidation v0.8.1 is released, supports Bootstrap 4 alpha 3

ip validator

Validate an IP address. Support both IPv4 and IPv6

Validators

Options

Option HTML attribute Type Description
ipv4 data-fv-ip-ipv4 Boolean Enable IPv4 validator, default to true
ipv6 data-fv-ip-ipv6 Boolean Enable IPv6 validator, default to true
message data-fv-ip-message String The error message
When setting options via HTML attributes, remember to enable the validator by setting data-fv-ip="true".
The message and other options can be updated on the fly via the updateMessage() and updateOption() methods

Example

It also supports CIDR notation:

<form id="ipForm" class="form-horizontal">
    <div class="form-group">
        <label class="col-xs-3 control-label">IP address</label>
        <div class="col-xs-7">
            <input type="text" class="form-control" name="ip" />
        </div>
    </div>
</form>

<script>
$(document).ready(function() {
    $('#ipForm').formValidation({
        framework: 'bootstrap',
        icon: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            ip: {
                validators: {
                    ip: {
                        message: 'Please enter a valid IP address'
                    }
                }
            }
        }
    });
});
</script>
<form id="ipForm" class="form-horizontal"
    data-fv-framework="bootstrap"
    data-fv-icon-valid="glyphicon glyphicon-ok"
    data-fv-icon-invalid="glyphicon glyphicon-remove"
    data-fv-icon-validating="glyphicon glyphicon-refresh">

    <div class="form-group">
        <label class="col-xs-3 control-label">IP address</label>
        <div class="col-xs-7">
            <input type="text" class="form-control" name="ip"
                data-fv-ip="true"
                data-fv-ip-message="Please enter a valid IP address" />
        </div>
    </div>
</form>

<script>
$(document).ready(function() {
    $('#ipForm').formValidation();
});
</script>

Related validators

The following validators might be useful to you: