Reputation: 29867
Ok, I've been using RegExp a number of times but for some reason I cannot get it to work this time. I am trying to test for latitude (0 to +/- 90 degrees). No matter what expression I use, it always returns false. Here's my code:
var regexLatitude = new RegExp("^-?([1-8]?[0-9]\.{1}\d{1,6}$|90\.{1}0{1,6}$)");
var status = regexLatitude.test("89.5");
I also tried without quotes:
var status = regexLatitude.test(89.5);
Any idea?
Upvotes: 1
Views: 151
Reputation: 887365
Your \
characters are being parsed by the Javascript string literal.
You need to use a regex literal:
var regexLatitude = /^-?([1-8]?[0-9]\.{1}\d{1,6}$|90\.{1}0{1,6}$)/;
Upvotes: 2