variable item validation for email in catalog item

patrycjabak
Tera Contributor

How can i make simple validaition for variable in maintain item ?

I need to validate email. it should contain "@" sign.
Regards,
Patrycja

5 REPLIES 5

Brad Tilton
ServiceNow Employee
ServiceNow Employee

I believe there is a variable type of email that will do this for you:



Types of service catalog variables


find_real_file.png
there is no email, thats my problem


What release are you on?



If you don't have that option available, you'll need to use a catalog client script to validate the variable. Here's a post that has a sample you can probably use:



Email address input validation service catalog


jmiskey
Kilo Sage

I was looking to do the same thing in the Service Portal.  I am on Jakarta, which does have the Email variable.  But unfortunately, that will not work for me.  If you click on the link in Brad's post, and go to the Email variable, it states right there:

Note: Variable validation is not supported in Service Portal.

 

So, I took a look at the other link referenced here, and was able to manipulate it to do what I need, and validate my variable in the Service Portal, using a Catalog Client Script.  

Here is the code that worked for me:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {	

	g_form.hideFieldMsg('group_contact_email_address');
	if (!isLoading && newValue !='') {		
		var inbox = g_form.getValue('group_contact_email_address');
		
		var validRegExp = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
		if (inbox.search(validRegExp) == -1){
			alert("Invalid Email Address!");
			g_form.setValue('group_contact_email_address','');
		}
	}
}