Arvin
Arvin

Reputation: 1014

jquery selector "contains" making error while using in chrome

I want to find whether the text in the input field contains any space character.For that I use the statement

$("#myTextBox").val().trim().contains(" ");

this should return true if the text in the textbox contains any space. But the problem is this is not working in Chrome and IE. It returns an error Uncaught TypeError: undefined is not a function in chrome's console. While in Firefox it is working fine. What would be the probable reason. Is it curable?

Please find the jsfiddle http://jsfiddle.net/1L1pf7c7/3/

Upvotes: 1

Views: 511

Answers (1)

Milind Anantwar
Milind Anantwar

Reputation: 82241

You can use indexOf(' ') with value to check space/whitespace character existence

if($("#myTextBox").val().indexOf(' ')>=0){
  //space exists
}

Demo

Upvotes: 1

Related Questions