Validate IP address using regex - Node.js Regular expression

Node.js examples for Regular expression:Validation

Description

Validate IP address using regex

Demo Code

Validator.validateIpadress = function(ip) {
    var exp = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
    if (ip.match(exp)) {
        return true;
    } else {//from www  . j av  a 2  s .  co m
        return false;
    }
};

Related Tutorials