Validate email field input
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2011 03:03 PM
I have a client script which will ensure input into an email field contains a valid email address:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
//If the page isn't loading
if (!isLoading) {
//If the new value isn't blank
if(newValue != '') {
//Type appropriate comment here, and begin script below
var oldV = oldValue;
validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
strEmail = g_form.getValue(email);
// search email text for regular exp matches
if (strEmail.search(validRegExp) == -1)
{
alert('A valid e-mail address is required.');
g_form.setValue('email',oldV);
}
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2017 12:29 PM
Sadly portal and mobile do not work with a get control ID so you can't use a drop in script like that in the portal.. HOWEVER if you functionalize the script and remove the control ID it SHOULD work perfectly.
Mobile Client GlideForm (g form) Scripting - ServiceNow Wiki
see section 2.1.5 and 2.1.6

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2017 10:40 AM
I use this in the Service Portal, and it works perfectly.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var email = newValue + '';
var regEx = new RegExp(/^(([^<>()\[\]\\.,;:\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,}))$/);
g_form.hideFieldMsg('u_personal_email');
if (!regEx.test(email)) {
g_form.setValue('u_personal_email', '');
g_form.showFieldMsg('u_personal_email', 'Please enter a valid email address', 'error');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2017 11:47 AM
I wrote about this approach in the SNStud.io blog: Validating Email Addresses in Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2017 12:43 PM
Did you try to just add an OOB email field to the form?
- Make the email field visible (need admin and elevated roles):
- akash.sharma@trianz.com wrote in the thread Email Field type validation that you will need to activate admin override in the write acl for "sys_glide_object".
- Make email field visible from Field class table.
- Add an field to your form.
Don't forget to de-activate admin override that you previously enabled.
harel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2017 12:48 PM
Email is only available as a type in Istanbul