- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2025 06:27 PM
Hi Team,
How to write catalog client script to give email validation as it can accept only abc.ab@(companyname).com users only. Need to valid it for 2 email domains. Abc.ab @(companyname1).com
Field is a single line text field(email Id).
@Ankur Bawiskar help on this used below code it is validating only one. Need to validate 2 email domains
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2025 07:11 PM
try this
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
g_form.hideErrorBox('variable');
// Updated regex to match the format abc.ab@company.com
var regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
newValue = newValue.toString();
var isValidFormat = regex.test(newValue);
if (!isValidFormat) {
g_form.showErrorBox('variable', 'Please enter a valid email address', 'error');
g_form.clearValue('variable');
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 08:14 AM
Sorry if you are asking the exact match then I already gave the code.
Please enhance it as per your requirement further.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2025 06:29 PM
This below code was working
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
g_form.hideErrorBox('variable');
var regex1 = /^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@companyname.com$/;
var regex2 = /^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@companyname1.com$/;
newValue = newValue.toString();
var isValidFormat1 = regex1.test(newValue);
var isValidFormat2 = regex2.test(newValue);
if (!isValidFormat1 && !isValidFormat2) {
g_form.showErrorBox('variable', 'Please enter valid email address', 'error');
g_form.clearValue('variable');
}
But need to modify were your email is in formate of abc.ab@company.com
@Ankur Bawiskar please help me on this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2025 07:11 PM
try this
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
g_form.hideErrorBox('variable');
// Updated regex to match the format abc.ab@company.com
var regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
newValue = newValue.toString();
var isValidFormat = regex.test(newValue);
if (!isValidFormat) {
g_form.showErrorBox('variable', 'Please enter a valid email address', 'error');
g_form.clearValue('variable');
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2025 07:21 PM
Replaced it with as you mentioned*.*@ab.com it's working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 07:16 AM
@Ankur Bawiskar as per the above it should take on abc.ab@company.com only but it is also accepting aba@company.com. it should not accept abc@company.com only should allow only abc.ab@company.com can you help me on this