Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Limitation to variable length in catalog item

SandeshR5514624
Tera Contributor

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.

 

 

 

2 REPLIES 2

ShubhamGarg
Kilo Sage

Hello @SandeshR5514624 ,

 

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

Rajesh Chopade1
Mega Sage

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