How to make a single line text to accept a only numbers and display custom message if string

avinashdube
Tera Guru

Hi , I have a requirement to make  a single line text to accept  only numbers and display custom message:

Quantity should be positive number and greater than 0.

I have used the regex but the it is showing this message :Not a number

 

1 ACCEPTED SOLUTION

You can find Regular expressions in "question_regex" table. You can create your own records and set the message.

Screenshot 2023-11-29 at 11.18.32 AM.png

View solution in original post

5 REPLIES 5

Anand Kumar P
Tera Patron

Hi @avinashdube ,

You can use below script i have tried in pdi its working.

AnandKumarP_0-1701237553489.png

 

AnandKumarP_1-1701237570354.png

 

AnandKumarP_2-1701237588491.png

 

AnandKumarP_3-1701237609072.png

 

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

   var regexp = /^[1-9]\d*$/;

if (!regexp.test(newValue)) {
    alert('Please enter a positive numeric value greater than 0.');
    g_form.setValue('get_validation', '');
}




   
}

Please mark it as solution proposed and helpful if it serves your purpose.

Thanks,

Anand