
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2019 09:02 AM
I want to be able to validate if an email address is in the correct format.
Validate this is valid email address xxxxx@xxx.xxx - if not valid email, pop "Please enter valid email address"
Is there a way to do that?
Thanks,
Karen
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2019 09:42 AM
There is an onSubmit client script included OOB with HR Service Management that has the following validation script:
function onSubmit() {
//Type appropriate comment here, and begin script below
g_form.hideErrorBox('email');
return validateEmail('email');
}
function validateEmail(field) {
var email = g_form.getValue(field);
if (!email || email.trim().length <= 0)
return true;
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,}))$/;
if (!re.test(email)) {
g_form.showErrorBox(field, getMessage('Invalid Email'));
return false;
}
return true;
}
You should be able to reuse this in a new client script for your issue.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2019 09:05 AM
You can use the email type field or variable which will automatically validate the email address

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2019 09:22 AM
Thank you for replying. I just made the variable of type Email; however, I was still able to submit the form.
So I am confused as to where it is validating the email address. And I don't want the form to be submitted if the email address is not of a valid format.
Thank you,
Karen

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2019 09:29 AM
I just tested in my instance and it is stopping from submission in both backend view and service portal.
May i know which version you are using?
You can try with the below onChange client script
var valid = validateEmail(newValue);
if (!valid)
g_form.showErrorBox('recipient_email', getMessage('Invalid email address'));
else
g_form.hideErrorBox('recipient_email');
function validateEmail(email) {
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,}))$/;
return re.test(email);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2019 09:42 AM
There is an onSubmit client script included OOB with HR Service Management that has the following validation script:
function onSubmit() {
//Type appropriate comment here, and begin script below
g_form.hideErrorBox('email');
return validateEmail('email');
}
function validateEmail(field) {
var email = g_form.getValue(field);
if (!email || email.trim().length <= 0)
return true;
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,}))$/;
if (!re.test(email)) {
g_form.showErrorBox(field, getMessage('Invalid Email'));
return false;
}
return true;
}
You should be able to reuse this in a new client script for your issue.