我有简单的检查
$(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/log1
,但在pattern
中有些错误 - 有时它会在好路径上触发,有时会跳过/var/www/logs/log'
(在结束')
应传递的列表示例:
/ var / www / logs / log
/ var / www / logs / log1
/ var / www / logs / log2
192.168.1.1
200
答案 0 :(得分:0)
如果您想匹配任何有效路径或仅匹配IP:
/ ^([\ / \瓦特] + |(([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 [O- 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