0

I have simple check

$(document).ready(function(){
    var pattern = /^[\.\/\w]$/;

    $('input[type="submit"]').click(function(){
        for (var i = 2; i < $('input[name="input_data[]"]').length; i++) {
            if(!pattern.test($('input:eq('+i+')').val())){
                console.log(pattern.test($('input:eq('+i+')').val()));
                console.log($('input:eq('+i+')').val());
                alert('Please doublecheck info.')
                return false;
            }
        }
    });
});

input:eq('+i+').val() is array of different file paths like /var/www/logs/log1, but something is wrong in pattern - sometime it fires just on good path, sometime skips /var/www/logs/log' (at the end ')

Example of list that should be passed:

/var/www/logs/log
/var/www/logs/log1
/var/www/logs/log2
192.168.1.1
200

Stephan
  • 41,764
  • 65
  • 238
  • 329
NoNameZ
  • 785
  • 4
  • 14
  • 22

1 Answers1

0

If you want to match any valid path or just an IP :

/^([\/\w.]+|(([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]))$/

/var/www/logs/log  => OK
/var/www/logs/log2 => OK
/var/www/logs/log' => NOK
/a/small/path/     => OK
192.1.168.23       => OK
Stephan
  • 41,764
  • 65
  • 238
  • 329