rhgiant — 2012-01-27T14:58:25-05:00 — #1
The current code returns true when it shouldn't... Can someone spot the issue?
var foo = /[a-z]/.test("12345");
sdleihssirhc — 2012-01-27T15:04:16-05:00 — #2
I got false when I ran it. What browser/os are you using? Is there context that might be messing with the results somehow?
rhgiant — 2012-01-28T07:16:13-05:00 — #3
var foo = /[a-z]/.test("aaa1");
sdleihssirhc — 2012-01-28T14:15:14-05:00 — #4
Ah, yes, that would be because your regex is only looking for a single character. It will return true if it finds any lowercase letter.
If you want to search the entire string... Well, there are a bunch of different ways you could do it; regular expressions are complicated. And I don't have a lot of experience with them, but this is what I would use, just off the top of my head:
// ^ means "start of string"
// * means "zero or more"
// $ means "end of string"
var foo = /^[a-z]*$/.test('aaa1');
alert(foo); // alerts "false"
rhgiant — 2012-01-29T10:42:11-05:00 — #5