Reputation: 19251
I am trying to get a simple regex to verify that a URL contains the ending figures
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');
}
And this should trigger alert('Not Match');
and it doesn't ? See http://jsfiddle.net/UgfKn/
What's going on ?
Upvotes: 4
Views: 8901
Reputation: 11087
You are missing !
in the if condition
if ( ! testRegex.test(imageUrl1) ) {
alert('Not Match');
}
See http://jsfiddle.net/UgfKn/1/
Upvotes: 0
Reputation: 56915
testRegex.test
will evaluate to True if testRegex
DOES match.
ie
if (testRegex.test(imageUrl)) {
alert('Match');
} else {
alert('Not match');
}
Upvotes: 1