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

@Saai1 try the below script:

 

^(?!65000|[6-9]\d{4}|[1-5]\d{5,})\d{1,5}$|^65000$

@Saai1 
Below regex, the key accepts a number from 1- 50000.
/^(?!5000[1-9]|0$|[5-9]\d{4}|[1-9]\d{5,})\d{1,5}$|^50000$/

 

range 1 to 65000 numbers

/^(?!6500[1-9]|0$|[5-9]\d{4}|[1-9]\d{5,})\d{1,5}$|^65000$/

I hope this helps!

 

Regards,

Hemant 

**Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.**

range 1 to 65000 numbers

/^(?!6500[1-9]|0$|[5-9]\d{4}|[1-9]\d{5,})\d{1,5}$|^65000$/

This is working from 1 to 49999 and also accepting 65000 but it is not accepting from 50000 to 64999. 

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)$/;

Eswar Chappa
Mega Sage
Mega Sage

Hi @Saai1 Please find the below client script which fulfill your functionality

 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }
    
    var validNumberPattern = /^(?:[1-9]\d{0,4}|50000)$/;
    
    if (!validNumberPattern.test(newValue)) {
        g_form.addErrorMessage('Invalid Number', 'Please enter a number between 1 and 50000.');
        g_form.setValue('description', ''); // Clear the field
    }
}

 

 

 

EswarChappa_0-1692794758263.png

EswarChappa_1-1692794780840.png

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