I'm trying to write a function that reads a inputs value, and determines if a space has been used in it's creation. I'm not trying to trim anything -- just see if it would have needed the ability to trim.
I'm not even sure where to begin on this, so I don't have any code to look at. Please help if you can!
I was trying this solution but it doesn't seem to work (I don't think I'm using .has() correctly)
if ($('#id').val().has(" ")) {
alert('has spaces')
}
Use val and indexOf :
var hasSpace = $('#myInputId').val().indexOf(' ')>=0;
If you want to test other types of "spaces" (for example a tabulation), you might use a regex :
var hasSpace = /\s/g.test($('#myInputId').val());
Demonstration
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With