What is the easiest way to check in Javascript whether the input text field is empty (contains nothing or white spaces only)?
var str = document.getElementById("myInput").value;
if (str.match(/^\s*$/)) {
// nothing, or nothing but whitespace
} else {
// something
}
You are looking for something like trim function, right?
Include this function somewhere (in order to provide a trim function)
String.prototype.trim = function () {
return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};
see here http://javascript.crockford.com/remedial.html
then...
if (document.forms['id_of_form'].elements['id_of_input'].value.trim()=='') {
//do xyz
}