How to set single line text variable length?

vl92
Kilo Contributor

How to set single line text variable length?

I want to set variable length to 20 characters.

Any one please suggest me.

9 REPLIES 9

Akash4
Kilo Sage
Kilo Sage

Hello, you can give them an alert saying the character limit must not exceed 20 characters and only the form gets submitted if it is less than 20.

Here is the code:

function onSubmit() {



  var text = g_form.getValue("u_epic_device_haiku_canto");



  var length=text.length;



if(length <40)



{



  alert("Please enter full field");



  return false;



}}

 

This is an onSubmit client script.

Regards, Akash
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.

@Akash4 is it possible to include another requirement where the value must start with a specific letter? I think the if statement will be if(startsWith !=c) but don't know to properly write the lines before. And the "C" doesn't have to be case sensitive

Mrigank Gupta
Giga Expert

Setting character limit is not supported.

You can write a onChange client script and check if the new value is more than 20, trim it to 20 characters and show an alert..Alternatively you can also write an onSubmit client script to verify it on submission of the form.

I would suggest for onChange as it will give the message at the same time and user will be well informed.

Zeeshan Khan1
Kilo Guru

Hi

 

If the catalog item isn't used on Service Portal, you can try below code :

This code needs to be written on onLoad client script.

g_form.getControl('var_name').setAttribute('maxlength', 20);