Expand my Community achievements bar.

SOLVED

Testing field validation

Avatar

Level 2

Hi all,

I am trying to test a phone number field for validation. I have the validation settings configured but I want to use the exit event to refocus on the field if the entry is wrong. As you may have seen you can enter an invalid phone number and it pops up the error then tabs to the next field.  I wish to move back the focus.  This is the code I have tried but I can't find the property list anywhere.  Can someone point me to the proper reference?

Using what property does the system set to true or false as part of validation so that I could use   (this.mysterypropertyIdontknow)

In the example below I made up the property "validated" to illustrate my goal.

Thanks in advance,

Tony.

javascript exit event:

if (!(this.validated)) xfa.host.setFocus(this.somExpression);

1 Accepted Solution

Avatar

Correct answer by
Level 10

Place a text field on the form.

Validate Pattern: text{9999999999}

Edit Pattern: text{9999999999}

Display Pattern: text{'('999') '999-9999}

//**** Copy the below code to Change Event
// restrict entry to digits
if (xfa.event.change.match(/[0-9]/) == null)
     xfa.event.change = "";

//**** Copy the below code to Exit Event
if(this.rawValue != null && this.rawValue != ""){
  if(!(this.tst)){
  //if Validate event does not get executed, this.tst value is coming as undefined, then force to execute the validate event
  if(this.tst == undefined){  
   this.execEvent("validate");
  }
  else{
    xfa.host.setFocus(this.somExpression);
   }
  }
}

//**** Copy the below code to Validate Event

var strPhoneNumber = "" + this.rawValue;
if(strPhoneNumber != "" || strPhoneNumber != null){
  this.formatMessage = "Please input a valid Telephone Number!";
  this.tst = false;
}
else
  this.tst = true;
  this.tst || Boolean(this.execEvent("exit"));
}

Thanks

Srini

View solution in original post

4 Replies

Avatar

Level 2

Try this:

onExit();

if

(this.rawValue != "" && this.rawValue != null)

{

if(!fieldValidator.validatePhone(this.rawValue))

{

xfa.host.messageBox("Invalid phone number pattern; it must be 10 digits:3334445555, 333.444.5555, 333-444-5555, 333 444 5555, (333) 444 5555")

phoneDr.rawValue

= "";

xfa.host.setFocus(phoneDr);

}

}

==================================================

function

validatePhone(field)

{

rePhoneNumber

= new RegExp(/^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/);

if (!rePhoneNumber.test(field))

{

return false;

}

return

true;

}

Avatar

Level 2

Thanks domahaMOO.

I didn't word my question very well.
Using the built in validation, does anyone know if acrobat sets a property that can be tested to find validation state?

If not, I can code the validation like your example.

I am still trying to get my footing with LC. (I use ES 8.2)

I have been trying to leverage the app's inherent ability trying to code as little as possible.

Avatar

Correct answer by
Level 10

Place a text field on the form.

Validate Pattern: text{9999999999}

Edit Pattern: text{9999999999}

Display Pattern: text{'('999') '999-9999}

//**** Copy the below code to Change Event
// restrict entry to digits
if (xfa.event.change.match(/[0-9]/) == null)
     xfa.event.change = "";

//**** Copy the below code to Exit Event
if(this.rawValue != null && this.rawValue != ""){
  if(!(this.tst)){
  //if Validate event does not get executed, this.tst value is coming as undefined, then force to execute the validate event
  if(this.tst == undefined){  
   this.execEvent("validate");
  }
  else{
    xfa.host.setFocus(this.somExpression);
   }
  }
}

//**** Copy the below code to Validate Event

var strPhoneNumber = "" + this.rawValue;
if(strPhoneNumber != "" || strPhoneNumber != null){
  this.formatMessage = "Please input a valid Telephone Number!";
  this.tst = false;
}
else
  this.tst = true;
  this.tst || Boolean(this.execEvent("exit"));
}

Thanks

Srini