how to write a script for only alphabet letters using ServiceNow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2022 11:16 PM
The employee name should contain only alphabets and space and not more than 30 characters on the whole. |
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2022 11:53 PM
1. Field should accept only string.
Create onChange Client Script on that particular field.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var field = g_form.getValue('fieldname');
if (!field.match(/^[A-Za-z ]*$/)) {
alert('Please enter only text');
g_form.clearValue('fieldname');
return false;
}
}
2. Limit length to 30 Characters.
Right Click on the field and click on Configure Dictionary and set max length to 30 like below screenshot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 01:03 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2022 09:49 AM
Thanks Raghu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2022 06:04 PM