Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript: ignoring case sensitivity of strings

In JavaScript, I'm trying using the user's input to search my database. For example, user input is "monster", and my database's data is "Monster". How can I have it match regardless of it's casing?

like image 795
Strawberry Avatar asked Apr 12 '10 00:04

Strawberry


People also ask

How do you ignore case-sensitive strings?

equalsIgnoreCase() method compares this String to another String, ignoring case considerations. Two strings are considered equal ignoring case if they are of the same length and corresponding characters in the two strings are equal ignoring case.

Are strings case-sensitive in JavaScript?

JavaScript is a case-sensitive language. This means that language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters.

Does JavaScript have an ignore case?

The ignoreCase property specifies whether or not the "i" modifier is set. This property returns true if the "i" modifier is set, otherwise it returns false.


1 Answers

Javascript string case-insensitive comparisons can be performed with string.toUpperCase.

if (input.toUpperCase() === "OTHER STRING")
    ....

(I'm assuming your database example is just an example as databases usually ignore the case of strings :)

like image 187
Gordon Gustafson Avatar answered Oct 12 '22 11:10

Gordon Gustafson