- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2016 05:59 AM
Hi All,
I am new to servicenow. I have field on form of type String and I want to validate it for only characters .
Please someone help me to achieve this.
Thanks in advance.
Chinnu
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2016 06:02 AM
Hi ,
write onChange() client script on a field as follwo
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var name=g_form.getValue('<field name>');
if (!isNaN(name))
{
alert("Only Characters are allowed");
g_form.setValue('<field name>','');
return false;
}
}
Thanks
Pradeep D J
PS - Please mark Helpful, Like, or Correct Answer if applicable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2016 06:02 AM
Hi ,
write onChange() client script on a field as follwo
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var name=g_form.getValue('<field name>');
if (!isNaN(name))
{
alert("Only Characters are allowed");
g_form.setValue('<field name>','');
return false;
}
}
Thanks
Pradeep D J
PS - Please mark Helpful, Like, or Correct Answer if applicable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2016 06:08 AM
Thank you Pradeep Its working for me.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2016 06:07 AM
I'll assume by 'characters' you mean letters (no numbers or special symbols.)
You can use an onChange or onSubmit client script and use a regular expression something like this: (NOTE: UNTESTED CODE AHEAD)
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (newValue === '') {
return;
}
var s = g_form.getValue('your_field_name');
var pattern = /[^A-Za-z]/g; // checks
if (s.search(pattern) >= 0) {
g_form.showFieldMsg('your_field_name', 'Only letters are allowed here', 'error');
return false;
} else {
g_form.hideFieldMsg('your_field_name');
return true;
}
}
Docs: Client Scripts
Docs: GlideForm
Client Script Best Practices - ServiceNow Wiki
TechNow Episode List (see episode 31)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2021 05:45 AM
Getting error message as " s is not a defined function() ";