0
Q:

compare string camelcase and lowercase javascript

var name1 = "Taylor Johnson";
var name2 ="taylor johnson";

//convert to lowercase for case insensitive comparison
if(name1.toLowerCase() === name2.toLowerCase()){
    //names are the same
}

2
str.toUpperCase() === str || str.toLowerCase() === str;
1
function sameCase(str) {
  return /^[A-Z]+$/.test(str) || /^[a-z]+$/.test(str);
}
0
var haystack = "A. BAIL. Of. Hay.";
var needle = "bail.";
var needleRegExp = new RegExp(needle.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), "i");
var result = needleRegExp.test(haystack);
if (result) {
    // Your code here
}
0

New to Communities?

Join the community