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

PK14
Kilo Guru

Hi @Ratnakar7  @Nilesh Pol1 @Peter Bodelier 

I already tried the max_length=10 thing but it doesn't work. User is still able to add more then 10 values. 

Please add a screenshot of the variable, with that attribute added.

Other option is to use Regex validation of course.
I wouldn't do this with a client script. This is not fool proof.


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

Make sure that the type of the variable is Single-line text or  Wide single-line text.   Else, it will not work.

 

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