How to ensure a single line text field in catalog form to only accept numeric values ?

Aditya Sinha
Tera Contributor

I have 4 single line text fields (A,B,C,D) which in my catalog form (Z) which need to only accept numeric values. How do I achieved this using a regex in a client script and a script include? [Will this regex work - 

RegExp('[0-9]+(,[0-9]+)+')]?

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

Since this is a variable in a Catalog Item, you can use Variable Validation Regex without a client script/script include.  This it the simplest regex to validate that the value is a number:

^[0-9]*$

 

Hi @Brad Bowman   where do I put this and what should be the variable type?

Variable Validation Regex is on the left nav

https://docs.servicenow.com/bundle/washingtondc-servicenow-platform/page/product/service-catalog-man... 

The variable type should be Single line text.  After you create the validation regex, you can select it for this variable on the Type Specifications tab.