- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2018 06:32 AM
How to restrict single line text variable for'' Limit to 50 characters. Check that only letters, numbers, dashes, and underscores are entered''.
Please suggest me any one.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2018 06:59 AM
Hi Naresh,
Here you go:
1) To limit 50 characters set max_length=50 in the attribute section for that catalog variable. so no need for regular expression for this.
2) Have onChange Catalog Client script to validate the values are number, dash, underscore etc. on that variable.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var validate = new RegExp('^[a-zA-Z0-9-_]+$');
// a-zA-Z means letter
// 0-9 means allow numbers
// - and _ means allow this characters
// try giving value with length as less than 50 and special character such as @ or ! and it should throw the alert message and clear the variable
var result = validate.test(newValue);
if(!result)
{
// value is invalid show alert message and clear the variable
alert('Please give only letters, numbers, dashes, and underscores');
g_form.clearValue('<variableName>'); // add variable name here
}
}
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2018 07:38 AM
Hi,
I need to restric special characters after 28 characters, this is possible