Expand my Community achievements bar.

Problem attempting to validate a simple zip code

Avatar

Former Community Member
Surely I'm missing something obvious but I've defined the validation pattern 'text{99999-9999} | text{99999}' on a text field for zip code entry. If I enter '12345' it works OK but '12345-1234' generates a validation error.



I'm also trying to define a valiation pattern for email addresses such as....



0+'@'0+'.'0+



... and having no luck. It always generates an error.
3 Replies

Avatar

Former Community Member
Rob,



You could try the following JavaScript (which uses a 'regular expression' to define a validation pattern) on the *exit event of your e-mail address field. In this example the email adress 'email' is on the first page of the form which has been named 'Page_01'. The names on your form could well be different.



// Validate the email address.



var e_mail = new RegExp();



// Set the regular expression to look for an email address in general form.

e_mail.compile("^[a-z0-9_\\-\\.]+\\@[a-z0-9_\\-\\.]+\\.[a-z]{2,3}$","i");



// Test the rawValue of the current object to see if it fits the general form of an email address.

if (e_mail.test(email.rawValue) == false)

{xfa.host.messageBox("Please enter a genuine E-mail Adress.","Invalid Information",0);

xfa.host.setFocus("form1.Page_01.email");

}



Regular expressions can look pretty daunting, but are a very powerful JavaScript feature that can prove to be invaluable for setting up data validation criteria. Any JavaScript (or Jscript) reference book or on-line tutorial will have a section showing you how to build them.



Hope this helps,



John

Avatar

Former Community Member
I've noticed that the answer to similar questions has often been 'use Javascript'.



I realise that the extensibility of Designer 7 via JS is a great feature for those who actually have that skill (and the time to script!).



However, many 'oridinary' users will want to do semi-complex validation and other time saving operations using GUI type methods, as indeed they can using the familiar MS Access dbms,



Rather than disappoint prospective users of Designer 8, it would probably be helpful if either more wizard-type help was offered for the above (again, as in MS Access longtime) or else Adobe took steps to advertise the fact that certain functionality required JS knowledge from the outset.



I know from experience that it can be frustrating for users to discover that they need to learn a whole new additional skill to use a product they have just purchased.



For many tasks Designer is very user friendly, so it would be great if certain not-so-basic-but-still-important functions were wizard-ised, methinks.

Avatar

Level 9
Hi Rob



A couple of things to try:

1. Remove the spaces around the | character in your expression.

2. Make sure you have exactly the same expression in your display pattern as you do in your validation pattern.



Let me know if this helps...



Howard