Alex Rivera | Logout

jQuery validate - how do I ignore letter case?

Asked 2011-02-22T23:24:19.617
10

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 :)

Edit
Report

2 Answers

2
return value.toLowerCase() == "atlanta";
or use
return value.toLowerCase() == "Atlanta".toLowerCase();
answered 2011-02-22T23:29:36.320
1
return (value ? value.match(/atlanta/i) : null) != null

This is case insensitive and you can do lots of fun stuff with the regex. Enjoy. And please don't do "Cosntant".toLowerCase() there is just too much wrong in that.

answered 2011-02-22T23:36:00.690

Your Answer