Reputation: 5585
How can I detect if an input field has at least one white space?
This is what I tried
if( $('#myVal').val().indexOf(' ') != 0 ){
///has at least a single white space within the string
}
Upvotes: 1
Views: 41
Reputation: 34152
You must compare indexOf to -1 not 0
if( $('#myVal').val().indexOf(' ') != -1 ){
///has at least a single white space within the string
}
Here is the DEMO
Upvotes: 2