limiting characters

PK14
Kilo Guru

Hello,

I've implemented a catalog onchange client script that effectively limits users to entering a maximum of 10 characters, which is functioning well. Presently, an alert is triggered only when a change or action is performed on the form. However, I'm seeking a solution that prevents users from typing more than 10 characters in the first place. Could you provide guidance on how to achieve this? I want the field to immediately block any further input after reaching the 10-character limit.Thank you for your assistance.

function onChange() {
var field = 'short_description';
var value = g_form.getValue(field);
if (value.length > 10) 
alert('The short description has exceeded the maximum character limit of 10 characters. Please ensure that the text length is within the allowed range.');
return false;
}
}

 

Regards,

Priyanka

7 REPLIES 7

Peter Bodelier
Giga Sage

Hi @PK14,

 

It is not needed to do this with a client script. 

Add a variable attribute: max_length=10


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Nilesh Pol1
Giga Guru

Hi @PK14 

 

Click on configure variable.Goto default Value tab-->in variable attribute field add below.

 

max_length=10

This will solve your issue.



Please mark Helpful, Like, or Correct Answer if applicable.

Ratnakar7
Mega Sage
Mega Sage

Hi @PK14 ,

 

You can either use Field validation: Regular Expressions or Add a variable attribute: max_length=10.

Thanks,

Ratnakar

Karthiga S
Kilo Sage

HI @PK14,

 

You can achieve this by using max_length attribute in service catalog variable.

 

max_length Sets the maximum number of characters allowed in the field. By default, the field accepts long strings of text, several thousand characters. Set the max_length attribute as appropriate for the information that the variable is collecting. For example, to allow for entry of an address, set max_length=200, or other appropriate length.

 

Applicable variables: Single-line text, Wide single-line text

 

KarthigaS_0-1693223585742.png

This worked fine in my case, it will not allow any character to be entered after 10 characters. Refer beow:

KarthigaS_1-1693223703014.png

 

Please mark it Correct and Hit Like if you find this helpful!

 

Regards,

Karthiga