Abhishek
Abhishek

Reputation: 2034

Underscore where: How to check for matching strings for case-insensitive

I'm using Underscore.js library to check for email address string inside my collection, if exists, like this:

var emailExists = this.model.get('emailmailCollection').where( {emailAddress:emailAddressValue});

It works perfectly for strings like [email protected], etc. but when I match emails like [email protected] & [email protected], it doesn't show it exists.

Is there a way to test for emails with case-insensitive in place.

Upvotes: 1

Views: 127

Answers (2)

kairocks2002
kairocks2002

Reputation: 446

Wherever you are getting [email protected], use the .toLowerCase() method on it and on your input. This way, all of your data is all lowercase.

For example:

console.log("Hello WOrLD".toLowerCase())

returns

hello world

this is a really amateurish way and probably won't work for you, but that's what I would try.

Upvotes: 0

yts
yts

Reputation: 1890

You can use filter instead.

var emailExists = this.model.get('emailmailCollection').filter(function(email){
   return email.get('emailAddress').toUpperCase() === emailAddressValue.toUpperCase();
});

Upvotes: 1

Related Questions