21

Вопрос по regex, javascript – Регулярное выражение для проверки IP-адреса

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

ValidIpAddressRegex = "^(([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])$";

Error: User Rate Limit Exceeded12345678Error: User Rate Limit Exceededtrue.. How to solve this?

Error: User Rate Limit Exceeded<code>\d</code>Error: User Rate Limit Exceeded<code>[0-9]</code>Error: User Rate Limit Exceeded<code>[0-9]</code>Error: User Rate Limit Exceeded<a href="https://stackoverflow.com/questions/16621738">stackoverflow.com/questions/16621738</a>

Dec 26, 2017, 4:05 PMотMarathon55

Error: User Rate Limit Exceeded

Apr 04, 2012, 7:12 AMотTJHeuvel

Error: User Rate Limit Exceeded<a href="https://superuser.com/questions/929153">superuser.com/questions/929153</a>

Sep 05, 2018, 3:04 PMотMark Bradley

21ответ

0

    import { Component } from '@angular/core';
    import { FormBuilder, FormGroup, Validators }   from '@angular/forms';

    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.scss'],
    })
    export class AppComponent {
      ipranging="";
      testForm1: FormGroup;
      testForm2: FormGroup;
      constructor(private fb: FormBuilder){

      }
      ngOnInit(): void {
        const ipPattern = 
        "(?:(?: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]?)";
        this.testForm1 = this.fb.group({
          inp: ['', Validators.pattern(ipPattern)],
          inp3: ['', Validators.pattern(ipPattern)]
        });
        this.testForm2 = this.fb.group({
          inp: ['', Validators.pattern(ipPattern)],
          inp2: ['', Validators.pattern(ipPattern)],
          inp3: ['', Validators.pattern(ipPattern)]
        });
        this.testForm2.setValidators(this.comparisionValidator);
      }

      public comparisionValidator(group: FormGroup) : any{

        const control1 = group.controls['inp'];
        const control2 = group.controls['inp2'];
        var control1array  = control1.value.split('.');
        var control2array = control2.value.split('.');

        if(parseInt(control1array[0]) > parseInt(control2array[0]) ){
          group.controls['inp3'].setErrors({ 'value2GreaterThanValue1': true });
          console.log(group); 
        }
        else if(parseInt(control1array[1]) > parseInt(control2array[1]) ){
          group.controls['inp3'].setErrors({ 'value2GreaterThanValue1': true });
          console.log(group); 
        }
        else if(parseInt(control1array[2]) > parseInt(control2array[2]) ){
          group.controls['inp3'].setErrors({ 'value2GreaterThanValue1': true });
          console.log(group); 
        }
        else if(parseInt(control1array[3]) > parseInt(control2array[3]) ){
          group.controls['inp3'].setErrors({ 'value2GreaterThanValue1': true });
          console.log(group); 
        }
        else {
          group.controls['inp3'].setErrors({ 'value2GreaterThanValue1': false });
          console.log(group);
        }   
      }
    }
0

for the pattern ex 192.168.23.28/255.255.255.0

^(25[0-5]|2[0-4][0-9]|[01]?[1-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-4]|2[0-4][0-9]|[01]?[1-9][0-9]?)\/(((128|192|224|240|248|252|254)\.0\.0\.0)|(255\.(0|128|192|224|240|248|252|254)\.0\.0)|(255\.255\.(0|128|192|224|240|248|252|254)\.0)|(255\.255\.255\.(0|128|192|224|240|248|252|254)))$

for the pattern ex 192.168.26.82/24 or 192.168.23.28/255.255.255.0

^(25[0-5]|2[0-4][0-9]|[01]?[1-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-4]|2[0-4][0-9]|[01]?[1-9][0-9]?)\/([1-9]|1[0-9]|2[0-9]|3[0-2]|(((128|192|224|240|248|252|254)\.0\.0\.0)|(255\.(0|128|192|224|240|248|252|254)\.0\.0)|(255\.255\.(0|128|192|224|240|248|252|254)\.0)|(255\.255\.255\.(0|128|192|224|240|248|252|254))))$

for the pattern ex 192.168.26.28

^(25[0-5]|2[0-4][0-9]|[01]?[1-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-4]|2[0-4][0-9]|[01]?[1-9][0-9]?)$

for the netmask ex 255.255.255.0

^(((128|192|224|240|248|252|254)\.0\.0\.0)|(255\.(0|128|192|224|240|248|252|254)\.0\.0)|(255\.255\.(0|128|192|224|240|248|252|254)\.0)|(255\.255\.255\.(0|128|192|224|240|248|252|254)))$
0

    <div style="text-align:left">
        <h2>Choose if you want to enter a single ip or range of ip's</h2>
      <select  [(ngModel)]="ipranging">
        <option  selected disabled value="none"> -- select an option -- </option>
        <option  value='ip'>Single Ip address</option>
        <option  value="range">Ip range</option>
      </select>
      </div>

    <form *ngIf="ipranging === 'ip'" novalidate [formGroup]="testForm1" class="render">
      <label>IP Address: 
        <input formControlName="inp" placeholder='0.0.0.0'/></label>
            <input formControlName="inp3" hidden/>
          <!-- <p *ngIf="testForm.controls.inp.status == 'INVALID' && testForm.controls.inp.value != ''" >Invalid</p>
          <p *ngIf="testForm.controls.inp2.status == 'INVALID' && testForm.controls.inp2.value != ''" >Invalid</p> -->
          <p *ngIf="testForm1.controls.inp.value != '' && testForm1.controls.inp.status == 'INVALID'" >Invalid</p>
    </form>

    <form *ngIf="ipranging === 'range'" novalidate [formGroup]="testForm2" class="render">
      <label>Starting IP:
        <input formControlName="inp" placeholder='0.0.0.0'/></label>
          <label>
              Ending IP:
            <input formControlName="inp2" placeholder='0.0.0.0'/></label>
            <input formControlName="inp3" hidden/>
          <!-- <p *ngIf="testForm.controls.inp.status == 'INVALID' && testForm.controls.inp.value != ''" >Invalid</p>
          <p *ngIf="testForm.controls.inp2.status == 'INVALID' && testForm.controls.inp2.value != ''" >Invalid</p> -->
          <p *ngIf="testForm2.controls.inp.value != '' && testForm2.controls.inp.status == 'INVALID' || testForm2.controls.inp2.value != '' && testForm2.controls.inp2.status == 'INVALID'" >Invalid</p>
          <p *ngIf="testForm2.controls.inp3.errors.value2GreaterThanValue1 == true">Starting IP is larger than the ending IP</p>
    </form>
0

Error: User Rate Limit Exceeded

ValidIpAddressRegex = "^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
1

Error: User Rate Limit Exceeded

^(([01]?[0-9]?[0-9]|2([0-4][0-9]|5[0-5]))\.){3}([01]?[0-9]?[0-9]|2([0-4][0-9]|5[0-5]))$
0

Error: User Rate Limit Exceeded

^((1?\d?\d|2[0-4]\d|25[0-5])($|\.(?!$))){4}$

Error: User Rate Limit Exceeded

0

Error: User Rate Limit Exceeded

function isSimpleIPv4( ip, u=true ) {
    if ((ip === undefined) || (ip === null) || (ip.length > 15)) return false;
    var p = ip.split(\'.\');
    if (p.length != 4) return false;
    p.forEach( function(v,k){p[k]=Number(v);} );
    if (isNaN(p[0]) || isNaN(p[1]) || isNaN(p[2]) || isNaN(p[3]) ) return false;
    if ((p[0] < 1) || (p[0] > 255) || (p[1] < 0) || (p[1] > 255) || (p[2] < 0) || (p[2] > 255) || (p[3] < 0) || (p[3] > 255)) return false;
    if (!u) return true;
    if ((p[0] > 223)) return 'multicast';
    if ((p[0] == 127)) return 'loopback';
    if ((p[0] == 10)) return 'RFC1918';
    if ((p[0] == 192) && (p[1] == 168)) return 'RFC1918';
    if ((p[0] == 172) && (p[1] >= 16) && (p[1] <= 31)) return 'RFC1918';
    return true;
}

Error: User Rate Limit Exceededif (isSimpleIPv4(ipString) !== true) console.log('Not a valid and useful IP address');

6

Error: User Rate Limit Exceeded

    /^(?:(?:2[0-4]\d|25[0-5]|1\d{2}|[1-9]?\d)\.){3}(?:2[0-4]\d|25[0-5]|1\d{2}|[1-9]?\d)(?:\:(?:\d|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5]))?$/

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

validates:
    0.0.0.0:0
    255.0.0.0
    192.168.1.0:8080
does not validate:
    192.168.0.0/24
    192.168..1
    192.168.1

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

    /^(?:(?:2[0-4]\d|25[0-5]|1\d{2}|[1-9]?\d)\.){3}(?:2[0-4]\d|25[0-5]|1\d{2}|[1-9]?\d)$/
31

Error: User Rate Limit Exceeded.Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded:Error: User Rate Limit Exceeded


Error: User Rate Limit Exceeded

^(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))$

Error: User Rate Limit Exceeded

0

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.Scanner;

class Solution{

    public static void main(String []args){
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            String IP = in.next();
            System.out.println(IP.matches(new MyRegex().pattern));
        }

    }
}

    class MyRegex{
        String pattern="^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\dCongrats, you solved this challenge!\\d?|2[0-4]\\d|25[0-5])$";

}
-1

Error: User Rate Limit Exceeded

^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$
12

Error: User Rate Limit Exceeded

^                           # START OF STRING
  (?=\d+\.\d+\.\d+\.\d+$)     # Lookahead, require this format: number.number.number.number END OF STRING
  (?:                         # Start non-capture group (number 0-255 + optional dot)
    (?:                         # Start non-capture group (number 0-255)
      25[0-5]                     # 250-255
      |                           # OR
      2[0-4][0-9]                 # 200-249
      |                           # OR
      1[0-9]{2}                   # 100-199
      |                           # OR
      [1-9][0-9]                  # 10-99
      |                           # OR
      [0-9]                       # 0-9
    )                           # End non-capture group
    \.?                         # Optional dot (enforced in correct positions by lookahead)
  ){4}                        # End non-capture group (number + optional dot), repeat 4 times
$                           # END OF STRING

Error: User Rate Limit Exceeded

^(?=\d+\.\d+\.\d+\.\d+$)(?:(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\.?){4}$

Error: User Rate Limit Exceeded

function isValidIpv4Addr(ip) {
  return /^(?=\d+\.\d+\.\d+\.\d+$)(?:(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\.?){4}$/.test(ip);
}
var testAddr = ['192.68.35.35','0.0.0.0','255.0.0.0','192.168.1.0','192.168.0.1','255.255.255.0','1.1.1.1','255.255.255.255','249.249.249.249','200.200.200.200','199.199.199.199','100.100.100.100','99.99.99.99','0.0.0.0','9.9.9.9','10.10.10.10','99.99.99.99','100.100.100.100','109.109.109.109','110.110.110.110','199.199.199.199','200.200.200.200','249.249.249.249','250.250.250.250','255.255.255.255','256.256.256.260','192.168.0.0/24','192.168..1','192.168.1','1','1.','1.1','1.1.','1.1.1','1.1.1.','1.1.1.1.','1.1.1.1.1','.1.1.1.1','01.01.01.01','09.09.09.09','1.0.0.1.0','010.1.1.1','123456','123123123123','.127.0.0.1'];
for (var i = 0; i < testAddr.length; i++) {
  document.getElementById('ipv4tests').innerHTML += '<li>' + testAddr[i] + ' ' + (isValidIpv4Addr(testAddr[i]) ? '<font color="green">VALID!</font>' : '<font color="red">INVALID!</font>') + '</li>';
}
<ul id="ipv4tests"></ul>

1

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded255Error: User Rate Limit Exceeded

^(([0-1]?[0-9]?[0-9]{1})|(2?[0-4]?[0-9]{1})|(25[0-5]))\.(([0-1]?[0-9]?[0-9]{1})|(2?[0-4]?[0-9]{1})|(25[0-5]))\.(([0-1]?[0-9]?[0-9]{1})|(2?[0-4]?[0-9]{1})|(25[0-5]))\.(([0-1]?[0-9]?[0-9]{1})|(2?[0-4]?[0-9]{1})|(25[0-5]))$
1

Error: User Rate Limit Exceeded

^((?:(?:^|\.)(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])){4})$

Error: User Rate Limit Exceeded.Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

0

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

var block "([0-1]{0,1}[0-9]{1,2}|2[0-4][0-9]|25[0-5]|)";
var ipv4 = "(" + block +"\\.){3}" + block ;

Error: User Rate Limit Exceeded

  • 000.12.12.034
  • 121.234.12.12
  • 23.45.12.56
  • 003.045.012.056
  • 03.45.12.6
  • 0.45.122.255
0

Error: User Rate Limit Exceeded

(((?<![\d])([0-9][\.])|(?<![\d])([1-9][0-9][\.])|(?<![\d])(1[0-9]{2}[\.])|(?<![\d])(2[0-5][0-5][\.]))(([0-9][\.])|([1-9][0-9][\.])|(1[0-9]{2}[\.])|(2[0-5][0-5][\.])){2}(([0-9])(?![\d])|([1-9][0-9])(?![\d])|(1[0-9]{2})(?![\d])|(2[0-5][0-5])(?![\d])))

Error: User Rate Limit Exceeded

Error: User Rate Limit ExceededError: User Rate Limit Exceeded

0

Error: User Rate Limit Exceeded

var aIP = [
  '192.168.0.1',
  '255.255.255.255',
  '1.2.34.647',
  '256.0.0.0',
  '255,0,0,0',
  '123.123.123',
  '1.2.3.4.5'
  ];

aIP.forEach(function(ipAddr) {
  
  var a = ipAddr.split('.'),
      cnt = 4;

  document.write('Testing ' + ipAddr + '<br/>');

  try {
    a.forEach(function(v) {
      if( v<0 || v>255 )
        throw false;
      cnt--;
    });
    if( cnt!=0 )
        throw false;
      cnt--;
    document.write('- Pass!<br/>');
  }
  catch (e) {
    document.write('- Fail!<br/>');
  }
});

3

Error: User Rate Limit Exceeded

^(([1-9]?\d|1\d\d|2[0-4]\d|25[0-5])(\.(?!$)|(?=$))){4}$

Error: User Rate Limit Exceeded

  function verifyIp(ip)
  {
    return /^(([1-9]?\d|1\d\d|2[0-4]\d|25[0-5])(\.(?!$)|(?=$))){4}$/.test(ip||"");
  }
  
  ["192.68.35.35","0.0.0.0","255.0.0.0","192.168.1.0","192.168.0.1","255.255.255.0","1.1.1.1","255.255.255.255","249.249.249.249","200.200.200.200","199.199.199.199","100.100.100.100","99.99.99.99","0.0.0.0","9.9.9.9","10.10.10.10","99.99.99.99","100.100.100.100","109.109.109.109","110.110.110.110","199.199.199.199","200.200.200.200","249.249.249.249","250.250.250.250","255.255.255.255","256.256.256.260","192.168.0.0/24","192.168..1","192.168.1","1","1.","1.1","1.1.","1.1.1","1.1.1.","1.1.1.1.","1.1.1.1.1",".1.1.1.1","01.01.01.01","09.09.09.09","1.0.0.1.0","010.1.1.1","123456","123123123123",".127.0.0.1"].forEach(function(item){
    is_valid = verifyIp(item);
    $('<div>'+item+' <span class="'+(is_valid?'correct':'wrong')+'">'+(is_valid?'VALID':'INVALID')+'</span></div>').appendTo('#result');
  });
.item {
  font-weight: bold;
}
.wrong {
  color: red;  
}

.correct {
  color: green;  
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="result"></div>

11

Error: User Rate Limit Exceeded

^(([1-9]?\d|1\d\d|2[0-5][0-5]|2[0-4]\d)\.){3}([1-9]?\d|1\d\d|2[0-5][0-5]|2[0-4]\d)$
1

Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded

^(((1?[1-9]?|10|2[0-4])\d|25[0-5])($|\.(?!$))){4}$

Match examples: Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

1

Error: User Rate Limit Exceeded

/^(?:(?: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]?)$/

RelatedQuestions