View Full Version : How To Validate Blanks, Spaces in Text Area

08-26-2004, 02:42 AM
I've the following code:

function validateText(fld, errMsg)
if(fld.value=="" || fld.value == " ")
alert("Please enter a value for " + errMsg + ".");
return false;
return true;
}//endfunction validatetext

However, it works only if there is a space, not when multiple spaces occur consecutively.

How do I make this validate if the user purposely enter spaces/blanks? :confused:

08-26-2004, 02:44 AM
Another thing, I tried searching if someone else had posted this by using the following keywords: validate space blank null.

No results. Maybe someone could kindly point me in the right direction if this question has been posted before.

Willy Duitt
08-26-2004, 04:33 AM
Try replacing: if(fld.value=="" || fld.value == " ")
With: if(fld.value.length == 0 || fld.value.match(/^\s+$/))


08-26-2004, 07:12 AM
Thanks Willy! :thumbsup:

Though There's a missing ) in the last part. :)

Willy Duitt
08-26-2004, 07:19 AM
Ooops... :D