I have to check some strings using JavaScript but case sensitivity is causing problems. for example
if('abc'=='ABC') { return true; }
it will not go inside the if loop though the meaning of the word are same. I cant use tolower clause too since i dont know the data how it would come it means for ex:
if('aBc'=='abC') { return true; }
how to write the JS function for this if it could be done by jquery.
The equalsIgnoreCase() method compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.
A general requirement while working in javascript is case-insensitive string comparisons.
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.
In JavaScript, strings can be compared based on their “value”, “characters case”, “length”, or “alphabetically” order: To compare strings based on their values and characters case, use the “Strict Equality Operator (===)”.
You can make both arguments lower case, and that way you will always end up with a case insensitive search.
var string1 = "aBc"; var string2 = "AbC"; if (string1.toLowerCase() === string2.toLowerCase()) { #stuff }
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