[英]Regex to match Image Url
我试图得到一个简单的正则表达式来验证URL包含结束数字
var testRegex = /^https?:\/\/(?:[a-z\-]+\.)+[a-z]{2,6}(?:\/[^\/#?]+)+\.(?:jpe?g|gif|png)$/;
var imageUrl = "http://stackoverflow.com/questions/406192/how-to-get-the-current-url-in-jquery";
if (testRegex.test(imageUrl)) {
alert('Not Match');
}
这应该触发alert('Not Match');
它没有? 见http://jsfiddle.net/UgfKn/
这是怎么回事 ?
你的意思是:
if (!testRegex.test(imageUrl)) {
alert('Not Match');
}
如果testRegex
匹配, testRegex.test
将评估为True。 即
if (testRegex.test(imageUrl)) {
alert('Match');
} else {
alert('Not match');
}
你错过了!
在if条件下
if ( ! testRegex.test(imageUrl1) ) {
alert('Not Match');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.