views:

54

answers:

3

I have this regular expression below to validate a security question where some one has to type in the answer twice. My client want the answers to be none case sensitive. So if someone types in Chester and the in the second field they type in chester it will match. What can I do to this expression to make that happen:

/^(\w|[a-zA-Z\d\s\.\@\-\?\,\&\/\_\#\+\(\)\""\'']){3,50}$/
+5  A: 

Simply append the i modifier:

/^(\w|[a-zA-Z\d\s\.\@\-\?\,\&\/\_\#\+\(\)\""\'']){3,50}$/i

Learn more about what the i modifier is and others here.

Jacob Relkin
That did not work
Amen
+2  A: 

Your regular expression already is case insensitive... and redundant. And that's all beside the point. You want to compare two fields, there's nothing regular expressiony about that. Here's your case insensitive field comparing function:

function fieldsMatch(input1, input2)
{
    return input1.value.toLowerCase() == input2.value.toLowerCase();
}
gilly3
A: 
// You can do it with a regular expression, if you insist.

function fieldsMatch(input1, input2){
    return /^([a-z\d\s\/.@?, &_#+()""''-]+)\1$/i.test(input1+ input2);
}

fieldsMatch('bone','BONE')


/*  returned value: (Boolean)
true
*/
kennebec