The CreatorCon Call for Content is officially open! Get started here.

How to set character limit of a variable.

shivani39
Tera Expert

Hi All,

How to set character limit for a variable. It should request you to enter a minimum of 8 characters to max limit. Allow up to 100 characters (w/spaces).

Thanks

1 ACCEPTED SOLUTION

shloke04
Kilo Patron

Hi,

Please write a On Change Catalog Client Script on your variable and use the script below:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    if (newValue) {
        var myFieldValue = g_form.getValue('Variable Name');
        if (myFieldValue.toString().length < 3) { // or whatever number you want
            g_form.setValue('your_field', '');
            alert('Please enter 3 or more characters.');
        }else if(myFieldValue.toString().length > 100){
			g_form.setValue('your_field', '');
            alert('Please enter less than 100 characters.');
		}
    }

    //Type appropriate comment here, and begin script below

}

 

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

2 REPLIES 2

Vinayak Belgaon
Mega Guru

You can use Regular Expressions to handle this 

/^.{1,10}$/.test(variable) // min - 1, max - 10

 

Mark helpful/correct if this resolved your query.

 

Regards

Vinayak

shloke04
Kilo Patron

Hi,

Please write a On Change Catalog Client Script on your variable and use the script below:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    if (newValue) {
        var myFieldValue = g_form.getValue('Variable Name');
        if (myFieldValue.toString().length < 3) { // or whatever number you want
            g_form.setValue('your_field', '');
            alert('Please enter 3 or more characters.');
        }else if(myFieldValue.toString().length > 100){
			g_form.setValue('your_field', '');
            alert('Please enter less than 100 characters.');
		}
    }

    //Type appropriate comment here, and begin script below

}

 

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke