...

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



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


function validateText(fld, errMsg)
{
if(fld.value=="" || fld.value == " ")
{
alert("Please enter a value for " + errMsg + ".");
fld.focus();
return false;
}//endif
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:

Kylena
08-26-2004, 03: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, 05:33 AM
Try replacing: if(fld.value=="" || fld.value == " ")
With: if(fld.value.length == 0 || fld.value.match(/^\s+$/))

.....Willy

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

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

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum