-1

How to search the word using jquery. I have used below code

child_name="Fasia_Cube.006";

if (child_name.toLowerCase().indexOf("fasia") >= 0){
    alert("fasia fond");
}

Fasic will come anyplace. How to solve this. Please any one help?

Yosvel Quintero
  • 18,669
  • 5
  • 37
  • 46
Shanmuga kumar
  • 165
  • 1
  • 4
  • 12

1 Answers1

0

Your code works fine.

But see that you can also use the String.prototype.search() method, that searches a string for a specified value, and returns the position of the match. The search value can be string or a regular expression. This method returns -1 if no match is found.

Note: Using regular expression and the flag i you do not need to call String.prototype.toLowerCase():

var child_name = 'Fasia_Cube.006';

if (child_name.search(/fasia/i) >= 0) {
  console.log('fasia fond');
}
Yosvel Quintero
  • 18,669
  • 5
  • 37
  • 46