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

Vishal Khandve
Kilo Sage

Hi Diane,

 

 

 

below thread will usefull to you..

 

ensuring a single line text field only has numbers

 

How to get an integer field on a catalog form

 

 

 

 

 

Thank you,

 

Vishu

 

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

Hello Rajesh,



Thank you so much for your help. But may I know how can I make this global so that I can only call the function names in scripts? Thank you!



Best Regards,


Diane Miro


Rajesh Mushke
Mega Sage
Mega Sage

Hey Miro,



Any update on this?



Would you mind please close this thread, then only this will be helpful for other community user.


thanks in advance.....!!!



If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.


If you are viewing this from the community inbox you will not see the correct answer button.   If so, please review How to Mark Answers Correct From Inbox View




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