I’m using the following javascript regex:
var pattern = new RegExp("^" + term + ".*")
console.log(pattern.toSource());
console.log(first_name + " : " + pattern.test(first_name) );
All i want it to do is check if the first name of the person begins with the search term given. E.g if the search term is ‘a’, then all the first names starting with a, e.g: andy, alice, etc should match. If its al, then only alice should match, etc. However the output is:
/^a.*/
Alyssa : false
What am I doing wrong?
There is nothing wrong, you should make the RegExp case insensitive using
to match your name as long you want to render the test case insensitive or use a match like
/^[aA].*/