P
Paul Lautman
Hi y'all,
I found this function at
http://www.devshed.com/c/a/JavaScript/Form-Validation-with-JavaScript/6/
// check to see if input is whitespace only or empty
function isEmpty(val)
{
if (val.match(/^s+$/) || val == "")
{
return true;
}
else
{
return false;
}
}
When I tried it it didn't work, but I found that I could make it work by
changing the regex to /^\s+$/
I then tried shortening it to:
function isEmpty(val)
{
return (val.match(/^s+$/) || val == "");
{
But this returns the value matched (when it is spaces).
Can someone answer the following 2 questions for me:
1) I'm sure that the function worked for the author (Nariman K), so why did
I need to add the escape character to get it to work?
2) If the expression evaluates to true/false for the purposes of the if
statement, why does it not return true/false reliably in the shortened form?
TIA
Regards
Paul
I found this function at
http://www.devshed.com/c/a/JavaScript/Form-Validation-with-JavaScript/6/
// check to see if input is whitespace only or empty
function isEmpty(val)
{
if (val.match(/^s+$/) || val == "")
{
return true;
}
else
{
return false;
}
}
When I tried it it didn't work, but I found that I could make it work by
changing the regex to /^\s+$/
I then tried shortening it to:
function isEmpty(val)
{
return (val.match(/^s+$/) || val == "");
{
But this returns the value matched (when it is spaces).
Can someone answer the following 2 questions for me:
1) I'm sure that the function worked for the author (Nariman K), so why did
I need to add the escape character to get it to work?
2) If the expression evaluates to true/false for the purposes of the if
statement, why does it not return true/false reliably in the shortened form?
TIA
Regards
Paul