Email validation to accept specified domain

gnunez
Kilo Guru

Hello all,

I need to come up with an email validation to only take the domain @calstate.edu. I found a great post in the community that excludes gmail and yahoo, but I'd think it would be easier to have a script that specified email should include @calstate.edu instead of continually stating yahoo, gmail, outlook, msn, etc. are all excluded.

Kind of got started using the following post found at: https://community.servicenow.com/community?id=community_question&sys_id=bd748f69dbd8dbc01dcaf3231f96...

Any help is greatly appreciated!

Thanks,

Grace

1 ACCEPTED SOLUTION

SanjivMeher
Kilo Patron
Kilo Patron

In the inbound action, you can add below condition to exclude emails from other domains

if (email.origemail.indexOf('@calstate.edu')>-1)

{

// Process my inbound actions

}


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

5 REPLIES 5

SanjivMeher
Kilo Patron
Kilo Patron

In the inbound action, you can add below condition to exclude emails from other domains

if (email.origemail.indexOf('@calstate.edu')>-1)

{

// Process my inbound actions

}


Please mark this response as correct or helpful if it assisted you with your question.

Sanjiv I'm using a catalog client script and it gives the error message but still allows the user to submit the request.

so users can get around this requirement by changing the email address after the error message shows

You need an onChange script as well as an onSubmit script. And return false in onSubmit

if (variable.indexOf('@calstate.edu')==-1)

{

g_form.addErrorMessage('Please enter a valid email');

return false;

}


Please mark this response as correct or helpful if it assisted you with your question.

Mike Patel
Tera Sage

Are you trying to validate in Inbound Action ? If so user below in condition field

email.from.toLowerCase().indexOf('@calstate.edu') != -1

 

For Client script use below

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	//If the page isn't loading and newValue isn't blank
	if (isLoading || newValue == '')
		return;
	
	// Compare string
	validRegExp = /^[a-zA-Z0-9._-]+@(calstate)\.edu$/i;
	strEmail = g_form.getValue('email_address');

	//search email text for regular exp matches
	if (strEmail.search(validRegExp) == -1) {
		alert('A valid @calstate.edu e-mail address is required.')
	}
}