Expand my Community achievements bar.

Spaces in Required Fields Negating Validation

Avatar

Former Community Member

Greetings!

I have required fields which are set up in "pages".  The user cannot proceed to the next page until the current page is complete (i.e. all required fields contain data).  Unfortunately, Adobe considers blank spaces (i.e. from the spacebar) as data, and therefore this allows the user to bypass the field validation for text fields (as long as no other validation requirement is present, e.g. zip code, email address, etc).  Does anybody know how to remove all spaces from a field if they are the only "characters" entered into a field, rendering the field value null?

Thanks in advance.

2 Replies

Avatar

Level 4

Ah....a problem I have struggled with myself. I am going to assume that you have a decent grasp of Livecycle and not delve into each aspect like how to open the Script Editor, but if I am wrong just let me know and I can expand on it.

On the field(s) that you wish to restrict spacing, create a Exit event with the following code:

var r = new RegExp("^[a-z,0-9]*$");

var result = r.test(this.rawValue);

if ( result != true )

{

    xfa.host.messageBox( "Enter alpha or numerical characters only. Do not enter spaces." );

    xfa.host.setFocus( this );

}

What should happen is that this will restrict the field from accepting either null values or blanks and only allow alpha or numberical characters and it should prompt the user. Also it should fix your data validation problem. I did test this out with a sample sheet that has a required field and a email submitt button and with this code it would not allow just spacing. One thing to keep in mind is how you have your fields setup. For example if you have one field for "Name" instead of "First Name" & "Last Name" it will error out. This snippet will not allow spaces anywhere.

Avatar

Former Community Member

Thanks for the reply, Josh. 

This is something I had considered, but unfortunately many of the fields are open text, like street address or "Explain Your Response Above", which require allowance of spaces.  This is something I could certainly use for fields that shouldn't have any spaces though. I would just need to include punctuation and special characters like @, &, and #.