0

我有简单的检查

$(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()是不同文件路径的数组,/var/www/logs/log1pattern/var/www/logs/log'

应通过的列表示例:

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

4

1 回答 1

0

如果您想匹配任何有效路径或只是一个 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
于 2012-09-26T13:00:17.977 回答