- 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
01-30-2018 06:50 AM
Hi Naresh,
You would require a regular expression for this.
I would come back and post the solution in some time for this.
Regards
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
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
01-30-2018 07:24 AM
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2019 05:33 AM
Ankur,
What if I wanted to set up the table column field attribute to validate that the form entry was in this format:
xxxx-xxxx-xxxx-xxxx and could not exceed 18 characters (allowing letters and numbers). This column in the table is a string type.
Thanks you for your time and assistance.
Larry