- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2023 10:56 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2023 01:29 AM
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');
}
}
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.
Please mark my solution as Accepted and helpful if my answer is helpful
Thanks and regards
Uday Kumar Valapudasu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2023 06:33 PM
Hi,
For Single line text variable you can use Validation Regex or create your own if OOB is not enough

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2023 11:19 PM
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
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2023 11:27 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2023 01:29 AM
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');
}
}
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.
Please mark my solution as Accepted and helpful if my answer is helpful
Thanks and regards
Uday Kumar Valapudasu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2023 06:33 PM
Hi,
For Single line text variable you can use Validation Regex or create your own if OOB is not enough