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?
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.
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.
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.
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With