Search code examples
javascriptjqueryjquery-mobile

How to check validation of IP Address in jquery


I need to add IP Validation in my project .Is there any function in jquery or in jquery mobile.So that it will validate the in put field?

Thanks


Solution

  • refer this document IP validation

    here he has used jqueryvalidator.js and explained with an example.

                $.validator.addMethod('IP4Checker', function(value) {
                    return value.match(/^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/);
                }, 'Invalid IP address');
    
                $('#form1').validate({
                    rules: {
                        ip: {
                            required: true,
                            IP4Checker: true
                        }
                    }
                });