- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2021 07:15 AM
Hi Team,
How to write catalog client script to give email validation as it can accept only @(companyname).com users only.
Field is a single line text field(email Id).
Thanks
Solved! Go to Solution.
- Labels:
-
Multiple Versions
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2021 10:25 PM
Not sure but that option should be there for single line text variable
If not then try to set it from List view of the variable if you don't wish to add to form layout
OR
you can create onChange client script on that variable and sample script below
UI Type - ALL
Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
g_form.hideErrorBox('variable');
var regex = /^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@companyname.com$/;
newValue = newValue.toString();
var isValidFormat = regex.test(newValue);
if(!isValidFormat){
g_form.showErrorBox('variable','Please enter valid email address','error');
g_form.clearValue('variable');
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2021 08:11 AM
Hi,
Make sure its Single line text field. If its still not there then add it from form layout.
Thank you
Prasad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2021 10:25 PM
Not sure but that option should be there for single line text variable
If not then try to set it from List view of the variable if you don't wish to add to form layout
OR
you can create onChange client script on that variable and sample script below
UI Type - ALL
Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
g_form.hideErrorBox('variable');
var regex = /^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@companyname.com$/;
newValue = newValue.toString();
var isValidFormat = regex.test(newValue);
if(!isValidFormat){
g_form.showErrorBox('variable','Please enter valid email address','error');
g_form.clearValue('variable');
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2021 12:35 AM
I believe I have answered your question by sharing 2 working solutions.
Please close the thread by marking my response as correct and helpful so that it helps future members.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2021 06:06 AM
Hi Ankur,
Thank you. your code is working as expected!
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2022 08:25 AM
Hi @ankur,
it's working for one email domain, what if we want to use 3 email domains?
Thanks.