Expand my Community achievements bar.

Validation syntax

Avatar

Former Community Member

What is the validation syntax ? I have tried usign the default email address in the field validation, (OOOOOOOO@'example.com') -- and that required that i use the example.com verbatim to pass validation. I tried to use some other formats, but non have worked the way i want yet. Is there some documentation regarding the way i can write validation patterns ?

4 Replies

Avatar

Former Community Member

If you are looking for straight e-mail address validation, this code can be placed directly into the exit event or modified to fit the validation event.

// Create the RegExp object

var r = new RegExp("[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?");

// Set the regular expression to look for  an email address in general form.
var result = r.test(this.rawValue); // Test the rawValue of the current object to see

// if it fits the general form of an email address.
if (result == true)
     true;          
else                    
{
     xfa.host.messageBox("Please enter a valid email address");
     xfa.host.setFocus(this);
}

Avatar

Former Community Member

Thank you for the reply.

When i put the code you sent into the script editor using javascript and the exit event. I do not see any results.

Also, i looked at the example you provided. I see that you are able to display a message box when the email doesn't pass validation, but are you able to stop them from submitting the form if the field is not valid? It would be nice to be able to write out a validation error list to the screen and not allow form submission until all fields passed validation on the client.

You mentioned the validation event. Would you please give more information on this ? I am very interested in the javascript methods, but would like to know all options for validation if possible.

Thanks much for any input.

Mike

Avatar

Level 5

I'm not able to get this to work right either.  I modified the script as below, and it seems to work when I put it in the Exit event.  But when I put in the Validate event, I get the validation error immediately upon opening the document -- why?

Thanks for any help.


var r = new RegExp("[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?");


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


if (result == false)


  {


  xfa.host.messageBox("Invalid e-mail address -- please use format username@domain.xxx","CHECK E-MAIL FORMAT",0,0);


  xfa.host.setFocus(this);


  }


Avatar

Level 5

Anyone out there that can help with this?