Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to verify and validate ip/cidr? #130

Open
yonatan92 opened this issue Jun 25, 2023 · 1 comment
Open

How to verify and validate ip/cidr? #130

yonatan92 opened this issue Jun 25, 2023 · 1 comment

Comments

@yonatan92
Copy link

I see only the option to validate ip without cidr

@makeupsomething
Copy link

There is no function for that, you can use this

function isValidCIDR(cidr: string) {
    try {
      const [range, bit] = cidr.split('/');
      const subnet = parseInt(bit);

    if(ip.isV4Format(range)){
        return subnet >= 0 && subnet <= 32;
    }else if(ip.isV6Format(range)){
        return subnet >= 0 && subnet <= 128;
    }
    return false;

    } catch {
      return false;
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants