Simple email validation in forms

Avatar

Avatar

Andrew_Smith_12

Avatar

Andrew_Smith_12

Andrew_Smith_12

13-09-2010

Hello All,

I would like to do a simple email validation, the built in email validation pattern(text{OOOOOOOO'@example.com'} ) is not really useful.

What is the best to validate an email in the form which was built using livecycle designer.

Is there any other pattern I can use?

My requirement is simple, the email should contain ‘@’ and a dot, something like ( xxx@xxx.xxx)

Any help is much appreciated.

Thanks and regards,

Accepted Solutions (0)

Answers (6)

Answers (6)

Avatar

Avatar

Andrew_Smith_12

Avatar

Andrew_Smith_12

Andrew_Smith_12

13-09-2010

I manage to solve the problem.

It is simple use the custom email address control.

Alternatively place the following javascript in normal textbox control.

// Validate the email address.

var

r = new RegExp("^[a-z0-9_\\-\\.]+\\@[a-z0-9_\\-\\.]+\\.[a-z]{2,3}$"); // Create a new Regular Expression Object.

// 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) // If it fits the general form,

  true; // all is well.

else

// Otherwise,

  false; // fail the validation.

Avatar

Avatar

Geckoz100

Avatar

Geckoz100

Geckoz100

18-11-2015

I added a couple of tweaks -- (1) to allow for up to 8-character domain suffixes (there are some long ones out there -- "museum", "travel", etc.);  (2) allows the user to leave the field empty with the initial if statement;  (3) if the field has content, the focus stays on the field if there's a validation error.  Thanks to OP Andrew Smith for the script.


if (this.rawValue != null) {


     // Create a new Regular Expression Object


     var r = new RegExp("^[a-z0-9_\\-\\.]+\\@[a-z0-9_\\-\\.]+\\.[a-z]{2,8}$"); // (allows 2-8 characters in domain suffix)


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


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


     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

Avatar

Geckoz100

Avatar

Geckoz100

Geckoz100

13-01-2015

Perfect -- works like a charm! (LCD ES2).

One question:  is there any way to make the focus stay on the e-mail field?  Because once it produces an error message due to invalid e-mail format, the focus moves to the next field anyway.

Avatar

Avatar

Geckoz100

Avatar

Geckoz100

Geckoz100

14-07-2016

FulufheloMM, could you please explain exactly how that works?

Avatar

Avatar

FulufheloMM

Avatar

FulufheloMM

FulufheloMM

12-07-2016

On a text box > Validation expression, add script below

(this.value && this.value.match(/^[A-za-z0-9]+[\\._]*[A-za-z0-9]*@[A-za-z.-]+[\\.]+[A-Za-z]{2,4}$/i) == null) ? false : true

this should solve your problem

Avatar

Avatar

TavC

Avatar

TavC

TavC

12-11-2014

Thanks for posting this