Regx help

Saai1
Tera Expert

Hi Everyone,

 

Need help in client script regex to allow only number form range 1 to 50000 in a single line text field.

 

Here is the regex I'm using and it is not working as expected. It allows till 50009. I want till 50000 only.

^(?:[1-9][0-9]?[0-9]?[0-9]?[0-9]?|1[1-5][0-9]?[0-9]?[0-9]?[0-9]?|2[0-4][0-9]?[0-9]?[0-9]?[0-9]?|25[0-5][0-9]?[0-9]?[0-9]?|6[0-4][0-9]?[0-9]?[0-9]?[0-9]?|50000)$

 

Thanks,

 

1 ACCEPTED SOLUTION

This is working.

 

/^([1-9]|[1-9][0-9]|[1-9][0-9]{2}|[1-9][0-9]{3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65000)$/;

View solution in original post

13 REPLIES 13

I'm using it on a single line text variable and it is still allowing 50001 till 50009. I want till 50000 only.

Hi @Saai1 Use the below script it was working

 

EswarChappa_0-1692795461611.png

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }
    
    var numericValue = parseInt(newValue, 10);
    
    if (isNaN(numericValue) || numericValue < 1 || numericValue > 50000) {
        g_form.setValue(control.name, oldValue);
        alert('Please enter a number between 1 and 50000.');
    }
}

It is not working on a catalog client script. Can you try on a single line text variable?

Hi @Saai1 sorry for the confusion,

 

use the below code in on change client script 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }
    
    var numericValue = parseInt(newValue, 10);
    
    if (isNaN(numericValue) || numericValue < 1 || numericValue > 50000) {
        if (newValue !== '') {
            g_form.clearValue(control.name, true); // Clear the field value
            g_form.showFieldMsg(control.name, 'Please enter a number between 1 and 50000.', 'error');
        }
    }
}

 

 

 

Please, Mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Best Regards,

Eswar Chappa