Last night I spent an anguishing two hours on this small problem, before getting badly irritated and watching half of a really horrid movie.



The Regexp.test(String) function in Javascript is called as:



/^[A-Za-z]/.test("abcd");



The above expression is to test weather a string starts with a letter or not.



This is NOT the same as:



var x = "/^[A-Za-z]/";

var y = "radio-gaga";

Regexp(x).test(y);





When you pass anything to the Regexp() constructor make sure it's not delimited by the '/'s. Ergo, what works is:



var x = "^[A-Za-z]";

var y = "radio-gaga";

Regexp(x).test(y);