- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2016 12:49 PM
I am currently looking at a Record Producer I created that needs to have many different fields that are inputting different emails. There are many articles that address the issue of email validation within a field, but I wanted to not have to modify each script individually if something needed changing. I came up with a number of options.
- Create Catalog Client Scripts for onLoad/onChange
- Too many fields to update and maintain. Makes me feel like less for not having a central function to rule them all.
- Use oob Service Now email validation
- Using the actual Email field Type, which does check the field automagically.
- This field type is hidden? Why?
- Should I override and un-hide email fields type?
- Reasons against or for?
- Using the actual Email field Type, which does check the field automagically.
- Another is using the built in function discussed in this article Validate Email field
- Can't get the code to work below in my Catalog Client Script:
- function onChange(control, oldValue, newValue, isLoading) {
- if (isLoading || newValue == '') {
- return;
- }
- //Email Validation Using OOB
- if(oldValue != newValue){
- g_form.hideFieldMsg('email', true);
- if (!isEmailValid(newValue)) {
- g_form.showFieldMsg('email', newValue + " is an invalid email, please re-enter email in correct format.",'error');
- }
- }
- Am I missing something on how to properly call this function?
- Can't get the code to work below in my Catalog Client Script:
- Create my own global Include/function
- Haven't dug into this one yet!
Thanks in Advance!
Jason M Fisher
University of Kentucky
ITSM Developer
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2016 05:09 AM
Well, I found some interesting stuff...
On line 9527 thru 9567:
Here's the actual code:
function isEmailValid(value) {
var problemMsg = isEmailValidWithReason(value);
if (problemMsg != "") {
jslog("isEmailValid: " + problemMsg);
return false;
}
return true;
}
function isEmailValidWithReason(value) {
var localPartChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%*/?|^{}`~&'+-=_.";
var domainChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.";
if (value.indexOf("@") == -1)
return "missing @ sign";
var s = value.split("@");
if (s.length != 2)
return "too many at signs";
if (!containsOnlyChars(localPartChars, s[0]))
return "invalid character before the at sign";
if (s[0].length < 1)
return "at least one character must be before the at sign";
if (s[0].substr(0, 1) == ".")
return "period cannot be the first character";
if (s[0].substr(s[0].length - 1, 1) == ".")
return "period cannot be the last character before the at sign";
if (!containsOnlyChars(domainChars, s[1]))
return "invalid character after the at sign";
var periodIndex = s[1].indexOf(".");
if (periodIndex == -1)
return "missing period after the at sign";
if (periodIndex == 0)
return "period cannot be the first character after the at sign";
var periods = s[1].split(".");
var lastPeriod = periods[periods.length - 1];
if (lastPeriod.length < 1)
return "must be at least 1 character after the last period";
if (!isAlphaNum(s[1].substr(0, 1)))
return "the first character after the at sign must be alphanumeric";
if (!isAlphaNum(s[1].substr(s[1].length - 1, 1)))
return "the last character must be alphanumeric";
return "";
}
Now, you can take that code and rename it and stuff it into your own Client Script or Script Include, or whatever you'd like.
Oh, they reference a function in there called containsOnlyChars() which can be found on lines 9855 thru 9864:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2016 12:08 AM
You can use isEmailValid(<email to validate>) function at client side to validate it.
For more details search Validation Script in navigator which has more validation scripts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2016 01:33 AM
Hi Rahul,
How can we use those Validation Scripts?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2016 08:42 AM
I imagine the other validation scripts are similar using a simple If statement captures a true/false and returns accordingly. I got isEmailValid to work properly by fixing my Error Message. Remember g_form.hideErrorBox("field_name", "Hello World")!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2016 05:43 AM
Thanks for the reply Rahul! Problem that I found is that the client script functions don't seem to run in Record Producers? In the code that I showed above, I am trying to use isEmailValid with no success.