Catalog Item validation for field email address

Arijit Saikia
Tera Contributor

Hi all,

I have a requirement for field validation of email address.

I have set the field type as email. The validation works fine when the user doesn't enter a valid email address and clicks submit.

However, the requirement is that there should be a on change script that validates the field as soon as the user moves to the next field, rather than validate at the submit stage.

 

Thanks

2 ACCEPTED SOLUTIONS

Uday_Kumar
Giga Guru

Hi @Arijit Saikia as you said your requirement to validate using script i am pasting the onchange script of validating gmail.com if you need any mails particular use or ( || ) gate 

OnChange Client Script :

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var mail = g_form.getValue('email');
    var at = 0;
    for (var i = 0; i < mail.length; i++) {
        if (mail[i] == "@") {
            at += 1;
        }
 }
    if ((mail.slice(-10) == '@gmail.com') && (at == 1)) {
        alert("valid gmail");
    } else {
        g_form.clearValue('email');
    }
}

Uday_Kumar_0-1679992066315.png

If it's a not valid email then it clears the entered value of email and user need to enter it's email again untill he entered the corrected email.

Uday_Kumar_1-1679992139539.png

 

Please mark my solution as Accepted and helpful if my answer is helpful

Thanks and regards

Uday Kumar Valapudasu

 

View solution in original post

Kamil Smusz
Kilo Sage

Hi,

 

For Single line text variable you can use Validation Regex or create your own if OOB is not enough

KamilSmusz_0-1680053569078.png

 

View solution in original post

4 REPLIES 4

Aman Kumar S
Kilo Patron

Hi,

 You can follow below article to achieve the same:

https://www.servicenow.com/community/itsm-articles/validate-email-id-using-regex/ta-p/2307653

 

Best Regards
Aman Kumar

Jaspal Singh
Mega Patron
Mega Patron

Hi Arijit,

 

Change the field type to Single Line Text ensure you set the Validation Regex as Email in the Type Specification tab of the variable form.

Uday_Kumar
Giga Guru

Hi @Arijit Saikia as you said your requirement to validate using script i am pasting the onchange script of validating gmail.com if you need any mails particular use or ( || ) gate 

OnChange Client Script :

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var mail = g_form.getValue('email');
    var at = 0;
    for (var i = 0; i < mail.length; i++) {
        if (mail[i] == "@") {
            at += 1;
        }
 }
    if ((mail.slice(-10) == '@gmail.com') && (at == 1)) {
        alert("valid gmail");
    } else {
        g_form.clearValue('email');
    }
}

Uday_Kumar_0-1679992066315.png

If it's a not valid email then it clears the entered value of email and user need to enter it's email again untill he entered the corrected email.

Uday_Kumar_1-1679992139539.png

 

Please mark my solution as Accepted and helpful if my answer is helpful

Thanks and regards

Uday Kumar Valapudasu

 

Kamil Smusz
Kilo Sage

Hi,

 

For Single line text variable you can use Validation Regex or create your own if OOB is not enough

KamilSmusz_0-1680053569078.png