top of page

Experiencing challenges with ServiceNow support?

IKC provides professional, reliable assistance that covers gaps not supported by ServiceNow

and without the high costs of traditional services.

 

Starting from just $1,000

How to Allow Only Numeric Data in Single-Line Fields in ServiceNow

Updated: Mar 29


When creating user-friendly forms in ServiceNow, ensuring the right type of input data is crucial. One common requirement is allowing users to enter only numeric values in single-line text fields or catalog item variables. This guide explains how to enforce numeric input validation effectively using client scripts and built-in ServiceNow functionality.


Common Issues with Numeric Input Fields

Users may sometimes inadvertently enter alphabetic or special characters into fields intended for numeric input only, causing data integrity issues. The lack of input validation can lead to inaccurate reports, processing errors, or operational inefficiencies. Addressing this issue proactively ensures a smoother user experience and reliable data handling.


Verified Methods to Allow Only Numeric Input

Here are practical solutions to ensure fields accept only numeric values in ServiceNow:


Method 1: Using a Client Script with Regular Expression

Implementing a client script is a straightforward way to enforce numeric validation:

Step-by-Step Guide:

  1. Create an onChange Client Script: Navigate to your catalog item or form, then define an onChange client script.

  2. Implement the Numeric Validation:

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

    var numericRegex = /^[+]?[0-9]*$/;

    if (!numericRegex.test(newValue)) {
        alert('Please enter a numeric value only.');
        g_form.setValue(control.name, '');
    }
}

This script triggers an alert and resets the field if the input is non-numeric.

Enhancing the Solution: You can limit input length by setting the variable attribute. For instance, adding max_length=3 restricts the input to three digits.


Method 2: Using Built-In Validation with Regex in Variable Settings

ServiceNow offers built-in functionality to enforce numeric validation without scripting:

Step-by-Step Guide:

  1. Navigate to Variable Settings: Go to your catalog item's single-line text variable.

  2. Set Validation Regex: In the "Type Specifications" tab, choose "Number" under "Validation Regex".

This built-in feature automatically restricts input to numbers and provides instant feedback to the user when invalid data is entered.


Alternative Solutions

Besides the methods mentioned above, you can also explore other options:

  • Global Function Implementation:You can create global client-side scripts to reuse numeric validation across multiple fields. Define your validation function in a script include or global UI script, then call the function within individual client scripts.

  • Server-Side Validation: For further robustness, complement client-side validation with server-side validation using business rules to ensure data integrity on form submission.


Conclusion

Implementing numeric validation in ServiceNow single-line fields helps ensure accurate data collection, reduces errors, and improves user experience. Whether using client scripts with regular expressions or built-in platform features, these methods provide reliable and efficient solutions to maintain data quality.

For best results, combine client-side and server-side validations and continually test configurations to align with evolving user needs and system requirements.

Experiencing challenges with ServiceNow support?

IKC provides professional, reliable assistance that covers gaps not supported by ServiceNow

and without the high costs of traditional services.

 

Starting from just $1,000

CONTACT

New Zealand HQ

Integrated Knowledge Consulting Office

Level 3, 93 Grafton Road

Auckland

South Korea

Integrated Knowledge Consulting Office

BMY역삼타워 6층

서울특별시 강남구 역삼동 678-10번지

 

info@ikconsulting.com

Thanks for submitting!

  • LinkedIn Social Icon

© Copyright 2025 Integrated Knowledge Consulting. All rights reserved.

bottom of page