- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 12:14 AM
Hi Team,
How to write catalog client script to give email validation as it can accept only @(companyname).com users only. Need to valid it for 2 email domains. @(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
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');
}
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 01:04 AM
update as this
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');
}
}
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-22-2025 01:10 AM
Thank you for marking my response as helpful.
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-22-2025 12:16 AM
try this
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
g_form.hideErrorBox('variable');
// Regular expression to validate both domains
var regex = /^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@(companyname\\.com|companyname1\\.com)$/;
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-22-2025 12:18 AM
try this
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 (!isValidFormat || !isValidFormat2) {
g_form.showErrorBox('variable', 'Please enter 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-22-2025 12:29 AM
Now it is not validating both email domains ankur. Can you recheck on this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 01:04 AM
update as this
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');
}
}
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