Expand my Community achievements bar.

Help with validation

Avatar

Former Community Member

Hi

I have the following code on change event of a field:

//Restrict the Length to the Maximum 5

var maxLength =5;

if(xfa.event.newText.length >maxLength)xfa.event.change = "";

// restrict entry to digits

if (xfa.event.change.match(/[^A-Za-z0-9]/))

       xfa.event.change = "";

and this code on the exit event of the same field

var minLength = 5;

    if(this.rawValue != null){

     if(this.rawValue.toString().length <minLength){

          xfa.host.messageBox("Please enter a minimum of 5 digits");

          xfa.host.setFocus(this);

          this.rawValue = ""

      }

}

else{

xfa.host.messageBox("Please enter a minimum of 5 digits");

     xfa.host.setFocus(this);

     this.rawValue = ""

}

this.rawValue =

this.rawValue.toUpperCase();

The validation works fine and won't accept anything less than 5 digits. But once I begin typing in the field and decide I no longer want to type in the field (its not a mandatory field) then it just wont let me out of the field. Keeps validating all the time.

Is there a way I can accept NULL values and also set the min length to 5 digits

Thanks

Andrew

1 Reply

Avatar

Former Community Member

It's probably empty string not null so this line is not working as you expect:

if(this.rawValue != null){