Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

This conversation has been locked due to inactivity. Please create a new post.

Formcalc: check for empty string in validate event

Avatar

Former Community Member
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>
2 Replies

Avatar

Former Community Member
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

Avatar

Former Community Member
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.