Validation required for email field

pramn
Tera Guru

Hi Team , 

Looking for email field validation field , once  validation failed there is a another field in the form called error  and it should be  checked in case of email validation failed . looking for Script include . 

Much appreciated your help in this 

 

find_real_file.png

8 REPLIES 8

Logan Poynter
Mega Sage
Mega Sage

Hello pramn,

What kind of validation are you needing to do against the email field? Clearer requirements will help provide a more accurate answer. 


Please mark my answer as correct/helpful if it has helped you.

Thanks,
Logan

Allen Andreas
Administrator
Administrator

Hello,

Unfortunately, you didn't provide any information as to how you're wanting to validate the email, but it would be recommended to use an email field/variable such as:

Email variable: https://docs.servicenow.com/bundle/rome-servicenow-platform/page/product/service-catalog-management/...

Or for email field, you can use onChange client script on the Email field with script such as:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') 
return;

function validateEmail(email) {
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,}))$/;
return re.test(email.toLowerCase());
}

if (!(validateEmail(newValue))) {
alert('Please provide a valid email address');
g_form.setValue('error_checkbox', true);
 }
}

The above is just an example. Change error_checkbox to the name of your error checkbox field name.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Actually clients looking for Script include ... honestly i am new with it .

PratyushaBodepu
Mega Guru

Hi @pramn , 

I have tried implementing the solution suggested by @Allen Andreas in my PDI and please find the details below.

There are 3 ways you can validate the email

Type 1: Email variable type - Below is how it will look, but setting the Error checkbox value might not be possible this way

find_real_file.png

Type 2:  A single line text field using the oob validation regex from the Type Specifications tab. This validates using the defined Question regular Expression validation as seen below. Setting the Error checkbox value might not be possible this way

find_real_file.png

find_real_file.png

Type 3: Using a client script to validate using a regex an set the Error Checkbox. upon invalid email address, throws an alert and sets the checkbox after clicking Ok. 

find_real_file.png

find_real_file.png

Please mark reply as Helpful/Correct, if applicable. Thanks!