- 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
01-22-2025 12:15 AM
Just tagged with new question pls check
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2021 01:16 AM
Hi,
I have created one 'single line text' variable in catalog in catalog item and one catalog client script.
I have applied onChange client script in email field, find below code for catalog client script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var email = newValue;
var emailPattern = /^[a-zA-Z0-9._-]+@companyname.com$/;
if (!emailPattern.test(email)) {
alert('Please enter valid email.');
} else {
alert('Entered email is correct.');
}
}
Thanks,
Mohit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2021 02:14 AM
Hello Gayathri,
use this line
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))*@companyname.com$/
I hope this will help you.
Mark ✅ Correct if this solves your issue and also mark ???? Helpful if applicable.
Regards,
Saurabh,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2021 11:57 PM
Hi,
Try below code ,
function onSubmit() {
var checkEmail= g_form.getValue('u_emailid');
var pattern=/^[a-zA-Z0-9]+@[a-z]{11}+\.[a-zA-Z]{2,4}$/;
if(pattern.test(checkEmail)){
alert("valid email id");
}
else{
alert("Invalid email id")
}
}
Please mark reply as Helpful/Correct, if applicable.
Thanks!!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2021 09:12 AM
Hello Gayathri,
Eg.
If Email ID requirement is like below:
/*
1. max length = 30
2. before @ 4 to 16
3. after @ and before . 3 to 10
4. ending with .com or .co.in
5. first letter small case alphabet
*/
The single line email validation using Regex is as follows :
var regex = [a-z][a-zA-Z0-9.-]{3,15}@[a-zA-Z0-9]{3,10}.(com|co.in)
Use this condition in your scripting.
I hope this will be helpful for you. If it is helpful, please mark the answer as Helpful.
Warm regards,
Rishikesh Kendale
