Is there a way to validate an email address

Cupcake
Mega Guru

I want to be able to validate if an email address is in the correct format.

Validate this is valid email address xxxxx@xxx.xxx - if not valid email, pop "Please enter valid email address"

Is there a way to do that?

Thanks,

Karen

1 ACCEPTED SOLUTION

Ian Mildon
Tera Guru

There is an onSubmit client script included OOB with HR Service Management that has the following validation script:

function onSubmit() {
   //Type appropriate comment here, and begin script below
   g_form.hideErrorBox('email');
   return validateEmail('email');
}

function validateEmail(field) { 
		var email = g_form.getValue(field);
		if (!email || email.trim().length <= 0)
			return true;
		var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
		if (!re.test(email)) {
			g_form.showErrorBox(field, getMessage('Invalid Email'));
			return false;
		}
		return true;
	}

You should be able to reuse this in a new client script for your issue.

View solution in original post

11 REPLIES 11

sumol
Giga Expert

Hi,

You can do this by UI policies. 

Step 1: Create a string variable.

Step 2: Create a UI policy having the following conditions

find_real_file.png

Step 3: Then write a script(Execute if false)

find_real_file.png

pawan k singh
Tera Guru

Other than using "email type" as a field, below background script always helped me for email validation.

Use this and customize wherever you need to validate email.

 

// Get email address from field
var emailAddress= "123gmail.com";

//If Email address is valid, take some aciton.For example printing success message below
if (/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))+$/.test(emailAddress)){
gs.info("Valid Email Address");
}

//If Email address is not valid, stop form submission or take some action
else{
gs.info("The email address format is invalid");

}

Regards

Pawan K Singh