Allow only numeric data in a single line field

dianemiro
Kilo Sage

Hi Everyone,

Does anyone here know how to allow only numeric data in a single line field? Majority, we will use it in catalog item variables so we want it to be global function and we will just call the function if we want to use it using client script. Thanks and I appreciate your help!

Best Regards,

Diane Miro

1 ACCEPTED SOLUTION

Rajesh Mushke
Mega Sage
Mega Sage

Hey Miro,

 

This is my script for accepting numbers only

 

function onChange(control, oldValue, newValue, isLoading) {

 

  if (isLoading || newValue == '') {

 

  return;

 

  }

 

  var regexp = /^[+]?\d*$/;

 

  if(!regexp.test(newValue)){

 

  alert('Please enter numeric value');

 

  g_form.setValue('v_sec_review_unknown','');

 

  }

 

}

 

 

 

in addition I defined "variable attributes   max_length=3" to accept up to 3 digits

 

 

 

This is one of my sources:

 

Regular Expression Library

 

 

 

You can also Refer:

 

RegEx in condition builder

 



Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke

View solution in original post

8 REPLIES 8

Ct111
Tera Sage

Hello , I know this solution is marked complete already but have a look at the OOB functionality as well in single line text field.

 

WHile creating a single line text variable you get a Type specification tab in that in Validation regex select Number and save the variable

 

Now whenever you are trying to put anything in the field apart from number it will give error...

 

find_real_file.png

 

 

How do you clear it if not a number in record producer OOB?

Faizanmazhar
Kilo Contributor

Wow nice.

Edxavier Robert
Mega Sage

Hi, just go to the field --> Type Specifications and in the Validation Regex --> select number

 

EdxavierRobert_0-1668173593599.png