
- 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:51 AM
Thank you I figured that part out after I replied back.
Much appreciated. This was my learn new item today.
Enjoy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2019 12:17 PM
Thank u very very much. I struggled 2 days for this task. Finally when i see this code tried working. Many thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2019 09:53 AM
For anyone looking for a solution to this.
In addition to the solution that Ian provided. I added an extra line of code so that it would provide a pop-up message asking to enter a Valid Email Address.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') return;
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.toLowerCase() );
}
if ( !window ) { // Only run in Service Portal
g_form.hideFieldMsg( 'wsa_email', 'true' ); // Hide any existing field messages
if ( !(validateEmail( newValue )) ) {
g_form.showFieldMsg( 'wsa_email', 'Invalid email address: ' + newValue, 'error', false );
alert('Please provide a valid email address');
g_form.setValue( 'wsa_email', '' ); // Clear out the invalid value
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2019 10:45 PM
Thanks for taking time to post this!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2019 07:45 AM
One thing I've always found a bit of a challenge is when I enter an incorrect email address and all I get back is a "slap on the hand" error message and then the email field clears out. Then I have to retype everything.
So, when I produce a showErrorBox(), I insert the value the user entered so they can copy/paste it back into the email field and make corrections rather than have to retype the entire thing.
I'm doing this now in a current project for all my showErrorBox() messages (where I clear out the field value).
var email = newValue.trim();
var isValidEmail = validateEmail(email);
if (!isValidEmail) {
g_form.setValue('u_email', '');
g_form.showErrorBox('u_email', "Please enter a valid email address. You entered: " + email);
}