For this , we can use jQuery function named as split().Using split() function we can check easily that whether a input string have spaces or not.
split function accepts first parameter a delimiter , second parameter is a string and split function splits the string into array by the given delimiter and returns string as same if in case there is no delimiter found.
Here is the code you have to use for this -
// id of the textbox is timeTaken
var strText = $.trim($('#timeTaken').val());
if(strText.split(' ').length > 1 )
{
console.log('no spaces please');
}
else
{
console.log('yep. correct.');
}
0 Comment(s)