Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery validate - how do I ignore letter case?

Probably a goofy question, but I can't seem to find anything in google land. I simply need one of my methods to ignore the case of the entered field. I am doing a city name match, but need both "Atlanta" and "atlanta" to be valid. How should I edit this to get the validation love that I need?

    jQuery.validator.addMethod("atlanta", function(value) {
    return value == "Atlanta"; //Need 'atlanta' to work too
}, '**Recipient must reside in Chicago City Limits**');

Pre thanks to any and all :)

like image 500
Jamie Avatar asked Feb 22 '11 23:02

Jamie


1 Answers

The easiest way to get a case-insensitive match is to convert both values to uppercase and then compare (uppercase because in certain cultures/languages the upper- to lowercase conversion can change a character!).

So make the check

value.toUpperCase() == "Atlanta".toUpperCase()
like image 152
wagi Avatar answered Dec 04 '22 17:12

wagi