PK-1825
PK-1825

Reputation: 1489

How to match uppercase and lower case letter in angularjs?

I want to match all upper case letter and lower case letter using regular expression, in my code I'm matching only particular character, but I want to match all character irrespective of capital or small. Here is my code

$scope.set_color = function(row) {
    var inputString = row.Subject;
    for (i = 0; i < inputString.length; i++) {
        //var findme = "HOT RUSH";
        //var str = findme.match(/\b([a-z][A-Z])\b/);
        var findmeCap = "HOT RUSH";
        var findmeSmall = "hot rush";
        if (inputString.indexOf(findmeCap) > -1 || inputString.indexOf(findmeSmall) > -1) {
            return {
                'background-color': '#FFCCCB'
            }
        }
    }
}

How I can do this?

Upvotes: 0

Views: 1488

Answers (3)

PK-1825
PK-1825

Reputation: 1489

Below code worked, in my case.

$scope.set_color = function (row) {
                       var inputString = row.Subject;
                       for (i = 0; i < inputString.length; i++) {
                           var findMe = "hot rush";
                           if (inputString.toLowerCase().indexOf(findMe) > -1) {
                               return { 'background-color': '#FFCCCB' }
                           }
                       }
                   }

Upvotes: 0

Krina Soni
Krina Soni

Reputation: 930

You can do string.toUpperCase and string.toLowerCaseAnd then compare the result. And change color accordingly result.

var a = "hello";
var b = "HELLO";  
if (a.toUpperCase() === b.toUpperCase()) {
   alert("string is equal");
   //change color 
}

Another solution is https://github.com/nickuraltsev/ignore-case

This works like that only so you can use any of these.

Upvotes: 2

Sreenivas Shenoy
Sreenivas Shenoy

Reputation: 182

var inputString = row.Subject;
var findMe = "hot rush";
if(inputString.toLowerCase().indexOf(findMe) !== -1) {
  return {'background-color': '#FFCCCB'};
}

This is how I would handle the problem.Regex is not what you need here. And get rid of the for loop.

Upvotes: 1

Related Questions