Email Validation for single line text field (Email ID)

GAyathri33
Tera Contributor

Hi Team,

 

How to write catalog client script to give email validation as it can accept only @(companyname).com users only.

 

Field is a single line text field(email Id).

 

Thanks  

1 ACCEPTED SOLUTION

@GAyathri 

Not sure but that option should be there for single line text variable

If not then try to set it from List view of the variable if you don't wish to add to form layout

find_real_file.png

OR

you can create onChange client script on that variable and sample script below

UI Type - ALL

Script:

 function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading) {
		return;
	}

	g_form.hideErrorBox('variable');

	var regex = /^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@companyname.com$/;

	newValue = newValue.toString();
	var isValidFormat = regex.test(newValue);

	if(!isValidFormat){
		g_form.showErrorBox('variable','Please enter valid email address','error');
		g_form.clearValue('variable');
	}

}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

21 REPLIES 21

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use Variable Validation Regex and no script required

1) create new variable validation regex

2) then add that in your variable

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Regex?

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Regex -> ^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@companyname.com$

find_real_file.png

Add to your variable

find_real_file.png

Output: Native

find_real_file.png

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

 

This option is not available in sandbox and dev

find_real_file.png