How to check textfield for whitespaces in jquery

html, javascript, jquery

Solution

In case you want to detect if there is any white space all through the user's input string,

var str = $("input").val();
if( str.indexOf(" ") !== -1 )
{
    alert("bad input");
}

Example: http://jsfiddle.net/pYquc/

Problem

I have a form. I want to put validation so that It will check if user enters white spaces or not. If its white spaces then show error. How could I do this?

Original source