Limitation to variable length in catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2024 02:23 AM
Hi Community,
I have requirement in which the max length of variable is 9, I have done that using max_length=9.
But how to set minimum variable length is 8 as well?
Or Maximum and minimum length should be same for variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2024 02:45 AM
Hello @sandeshraut198 ,
Use regular expressions to fulfill this criteria.
Go to your variable > "Type specifications" section > Select appropriate Validation Regex from drop-down list. > Save it.
In case, RegEx is not present in drop-down. Create new Validation Regex following this path: Service catalog > Variable Validation Regex > Create New.
Mark this response as correct/helpful if you find it helpful.
Regards,
Shubham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2024 03:21 AM
Hi
catalog variables don't have a direct way to set a minimum length through the system's standard properties like max_length.
You can achieve it by using client script (onSubmit / onChange)
Following script will help you for this:
function onSubmit() {
var fieldName = 'variables.your_variable_name'; // Replace with your variable's name
var fieldValue = g_form.getValue(fieldName);
if (fieldValue.length < 8 || fieldValue.length > 9) {
g_form.addErrorMessage('The field must be exactly 8 or 9 characters long.');
g_form.showFieldMsg(fieldName, 'The field must be between 8 and 9 characters long.', 'error');
return false; // Prevent form submission
}
return true; // Allow form submission
}
I hope my answer helps you to resolve your issue, if yes please mark my answer correct & helpful.
thank you
rajesh