Nodejs Utililty Methods IP Address Format Check

List of utility methods to do IP Address Format Check

Description

The list of methods to do IP Address Format Check are organized into topic(s).

Method

ipv4Address()
String.prototype.ipv4Address = function() {
  return /^(([1-9]?\d|1\d\d|2[0-4]\d|25[0-5])(\.(?!$)|$)){4}$/.test(this);
};
ipv4Address()
String.prototype.ipv4Address = function() {
  return /^(([1-9]?\d|1\d\d|2[0-4]\d|25[0-5])(\.(?!$)|$)){4}$/.test(this);
};
ipv4Address()
String.prototype.ipv4Address = function() {
  var ipv4 = this;
  if(ipv4.trim().length!=ipv4.length) return false;
  var arr = ipv4.split('.');
  if(arr.length!=4) return false;
  for(var i=0; i<arr.length; i++){
    if(!(checkWhiteSpace(arr[i]) && checkLeadZero(arr[i]) && checkForNum(arr[i]))){
      return false;
  return true;
};
function checkWhiteSpace(str){
  return str.trim().length == str.length;
function checkLeadZero(str){
  if(str.length==1) return true;
  if(str.charAt(0)==0) return false;
  if(str.charAt(0)=='+') return false;
  else return true;
function checkForNum(str){
  var num = parseInt(str);
  if(num>=0 && num<=255) {
    return true;
  }else {
    return false;
ipv4Address()
String.prototype.ipv4Address=function(){
  var newArr = this.split('.');
  if(newArr.length !== 4){
    return false;
  var test1 = this.split('.').join('');
  var regexp = new RegExp("\\D+", "g");
  if(regexp.test(test1) === true){
    return false;
...