Validate IP address by regex - Node.js Regular expression

Node.js examples for Regular expression:IP Address

Description

Validate IP address by regex

Demo Code



function checkIp() {
  var ip = document.getElementById('text3');
  var filter = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/;
  if (!filter.test(ip.value)) {
    alert('Please enter valid IP address');
    ip.focus;/*w w w  .j  a v  a2 s  .  co m*/
    return false;
  }
  return true;
}

Related Tutorials