Formcalc: check for empty string in validate event | Community
Skip to main content
March 9, 2008

Formcalc: check for empty string in validate event

  • March 9, 2008
  • 2 replies
  • 7225 views
I try to use a validate event to prevent an empty string. So I used this little Formcalc script: (I prefer Javascript as well. Yet I felt it should be possible with Formcalc as well)



<pre>

if ($ == "") then

0;

else

1;

endif

</pre>



This validate event never returns 0 :-(

Does anyone have an explanation for this behavior of Formcalc?



By the way: The following line does the trick in Formcalc:

<pre>

if ($.isNull )

</pre>
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

March 13, 2008
An empty string and a null string are two different things. Null means it doesn't exist, whereas "" means it exists but the value is empty. It's good coding practice to check for both null and empty string values.

Another thing that is common to do is to check to make sure the value isn't all whitespace (spaces and/or tabs). You can use Ltrim and Rtrim to strip out the leading and trailing whitespace. Use the following code as an example:



var thevalue = Rtrim(Ltrim($));

if (thevalue == "" | thevalue == null) then

0;

else

1;

endif



Hope this helps!

Justin
March 16, 2008
Justin,

I tried this one. It did not work.

I added a messagebox before returning 0 or 1. This way I found out that the valdidate fires only on "change" (not upon leaving the focus of any field as described in the manual).

And actually it appears that the validate event never fires when the field contains an empty string.