- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2018 09:09 PM
I had created some validation in Client Script for my page but now i want to create them in Script Include and call it like a function in my Client Script. And have some troubles here ! Example:
This is my CLient Script for email validate
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// var input = g_form.getValue('email');
// var answer = true;
// var regex = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/ig;
// if(!input.match(regex)){
// g_form.addErrorMessage('Email is invalid format ! (abc@domain.com)');
// answer = false;
// g_form.clearValue('email');
// setTimeout(function(){
// g_form.clearMessages();
// }, 5000);
// }else{
// return true;
// }
var ga = new GlideAjax('emailValid');
ga.addParam('sysparm_name','isEmail');
ga.addParam('sysparam_id',newValue);
ga.getXML(Process);
}
function Process(response) {
var answer = true;
var email = g_form.getValue('email');
if (!email.match(isEmail(email))){
g_form.addErrorMessage('Email is invalid format ! (abc@domain.com)');
answer = false;
g_form.clearValue('email');
setTimeout(function(){
g_form.clearMessages();
}, 5000);
}
}
And here is what i just did with Script include
var emailValid = Class.create();
emailValid.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
isEmail: function(email){
var regex = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/ig;
return regex.test(email);
},
type: 'emailValid'
});
pls help me solve this !
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2018 05:30 AM
Hi escanor,
Remove the line var answer = true and replace with
var ans = response.responseXML.documentElement.getAttribute('answer');
if(ans == 'false')
{
g_form.clearValue('email');
g_form.clearMessages();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2018 09:21 PM
Hi escanor,
Something like below is missing from your client script under Function Process(response)
var ans = response.responseXML.documentElement.getAttribute('answer');
Take the below sample as reference for client script.
var glaj = new GlideAjax('learn');
glaj.addParam('sysparm_name','passion');
glaj.addParam('sysparm_dimple',newValue);
glaj.getXML(callkaru);
function callkaru(response)
{
var ans = response.responseXML.documentElement.getAttribute('answer');
alert(ans);
}
And I also want to know that why are you validating two times once in Script Include and Once in client script
by using that IF loop under process function .
PLEASE let me know your response.
Mark my ANSWER as CORRECT if it helped you in achiveing sol.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2018 11:39 PM
I want to create in Script Include so another one can call my function to use in another page in the same project
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2018 05:30 AM
Hi escanor,
Remove the line var answer = true and replace with
var ans = response.responseXML.documentElement.getAttribute('answer');
if(ans == 'false')
{
g_form.clearValue('email');
g_form.clearMessages();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2018 08:13 PM
Ty bro ! it's worked !