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

avinashdubey103
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

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

5 REPLIES 5

Anand Kumar P
Giga Patron
Giga Patron

Hi @avinashdubey103 ,

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