How to define a range specification in client scripts

Mi1
Tera Contributor

Hi,

I don't want to let you enter certain numbers.

Example) Allow the input of numbers other than 1-10. 

Can I define a range specification in client processing?

Regards,

1 ACCEPTED SOLUTION

so you want to allow numbers from 151? In that case you dont need regex. Regex is used to validate formats.

You can use client script for this

var x = g_form.getValue('fieldname');

if ( x >100 || x <= 150)

{

alert("Numbers cannot be between 100 and 150);

}

Regards
Harish

View solution in original post

8 REPLIES 8

Harish KM
Kilo Patron
Kilo Patron

you can do something like this

function onChange(control, oldValue, newValue, isLoading) {
if(isLoading || newValue == ''){
return;
}

var pattern = /^([5-9][5-9]{0,2}|1000)$/;
if(!pattern.test(newValue)){
g_form.showFieldMsg('number', 'Please enter a  number between 5 to 5000', 'error');
}
}

Regards
Harish

Mi1
Tera Contributor

Hi,

Thank you.

What does this phrase mean? How can I write code when I don't want to let a number between "100-150" be entered?

Regards,

so you want to allow numbers from 151? In that case you dont need regex. Regex is used to validate formats.

You can use client script for this

var x = g_form.getValue('fieldname');

if ( x >100 || x <= 150)

{

alert("Numbers cannot be between 100 and 150);

}

Regards
Harish

Mi1
Tera Contributor

Hi,
Thank you.

I worked it.

Best Regards,