javascript表达式举例:
举例:匹配IP地址 100.4.5.6
var reg = /^(
(?: (?: 25[0-5] | 2[0-4] \d | ( (1\d{2}) |([1-9]?\d)) ) \. ) {3}
(?:25[0-5]|2[0-4] \d | ( (1\d{2}) | ([1-9]?\d) ) )
) $/;
alert("请输入正确的IP");
return false;
}
举例:匹配路径 /home/project
var reg = /^([/]{1}[a-zA-Z0-9]+)*$/; 或者var reg = /^([/][a-zA-Z0-9]+)*$/;if (!reg.test( path )) {
alert("路径不符合规范");
return false;
}
原文链接:https://www.f2er.com/regex/358794.html