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
‎07-07-2017 04:52 AM
Hi
I am unable to find isEmailValid() function. Could you please tell us where we can find this function in API.
Thanks in Advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-14-2012 12:00 PM
Has anyone tried the script provided by Matt and had it work? We have tried it in two different places in our QA environment and not had any luck. Any input is appreciated!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2015 12:42 PM
I use the below as an onchange script for the field being validated.. one thing you may want to incorporate that i did was the var err_field=control.id;
this makes the code portable.. you just drop it into the onchange script and set the field you are watching and it will get the name of the field for the script by itself.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//validates a valid email address for the onchange field
var err_field = control.id;
var err_message = 'Invalid Email Address (abc@domain.com)',
regex = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/ig;
var err_flag = 'false';
err_flag = regex.test(g_form.getValue(err_field));
g_form.hideErrorBox(err_field);
if (!err_flag) {
g_form.showFieldMsg(err_field, err_message, 'error');
}
else { g_form.hideErrorBox(err_field); }
}
for those that want it the below does phone numbers <us only>
On change script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//checks the variable the onchange is for to verify it is a valid phone number
var phone_field = control.id;
g_form.hideFieldMsg(phone_field);
var intNum = g_form.getValue(phone_field);
if (!isPhoneDash(intNum))
{
g_form.showFieldMsg(phone_field,'Invalid Phone Number Value ###-###-####','error');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2017 08:02 PM
Raymond these are elegant and very useful. I'm new to admin and this is a huge help (took me forever to find but I'm so glad I found your script). Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2017 11:40 AM
Hey Raymond,
Would you know how to make that script work in Service Portal?
Thanks