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 Enforce Numeric Input in ServiceNow Service Catalog Variables


Are you looking to ensure users enter only numeric values, like phone numbers, in your ServiceNow service catalog variables? Enforcing data type restrictions improves data quality and prevents errors in your ServiceNow workflows. This article provides a comprehensive guide on how to achieve this, ensuring accurate data capture within your ServiceNow instance.


Restricting Input to Numeric Values


ServiceNow's service catalog often requires users to input specific data, such as phone numbers or employee IDs. If a variable is set up without proper validation, users can inadvertently enter non-numeric characters, leading to data integrity issues and process breakdowns. Traditionally, developers used scripting to solve this. However, more recent ServiceNow versions offer no-code solutions making implementation easier.


Solutions for Numeric Value Restriction in ServiceNow


Let's explore two primary methods for limiting variable input to numeric values within ServiceNow. The first utilizes a client script, while the second (available in newer ServiceNow instances) employs a straightforward configuration setting.


Solution 1: OnChange Client Script


This method involves creating an OnChange client script that triggers whenever the value of the variable changes. This script verifies if the entered value is numeric, alerting the user if it's not, and clearing the invalid input.


Here's how to implement it:


  1. Navigate to Client Scripts: In ServiceNow, go to "Service Catalog" > "Client Scripts" and click "New."


  2. Configure the Client Script:

    • Name: Provide a descriptive name (e.g., "Validate Phone Number").

    • Catalog Item: Select the specific catalog item containing the variable you want to validate.

    • Type: Choose "OnChange."

    • Variable Name: Select the target variable.

    • UI Type: Choose "All" or "Desktop" depending on your needs.

    • Active: Set to "True."


  3. Write the Script: Copy and paste the following script into the "Script" field. Adapt it to match your variable name:

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

    if(isNaN(newValue) == true){
       alert("Please enter numeric values only in the phone number field");
       g_form.setValue('variable_name', ''); // Replace 'variable_name' with your variable's name
    }
}

  1. Adjust Maximum Length: To limit the number of digits (e.g., to 10 for a phone number), open your variable. Locate the "Attributes" field (you may need to configure the form layout to see this). Enter max_length=10 (or your desired length). This attribute limits the number of characters the user can enter into the variable.


  2. Save the Client Script: Click "Submit."


How the Script Works

  • isNaN(newValue) == true: This checks if the input newValue is not a number. The isNaN() function returns true if the value is "Not-a-Number."

  • alert(): Displays an error message to the user.

  • g_form.setValue(): Clears the variable, prompting the user to enter a valid number.


Solution 2: Using Validation Regex


Modern ServiceNow versions (Orlando and later) have streamlined this process. You can now use the “Validation Regex” feature. Here’s how to configure this feature:

  1. Open Variable Definition: Open the Service Catalog item and go to the specific variable for which you want to set up the rule.

  2. Type Specifications: Under Type Specifications related link or tab, select 'Single Line Text' variable

  3. Validation Regex: Under Validation Regex select 'Number'.

Advantages
  • Simple to setup : Minimal configuration needed with no coding involved.

  • User-friendly : Standard ServiceNow validation which provides a smooth user experience.

Alternative Solutions to consider

  1. Regular Expressions in Client Scripts: While the isNaN() function is simple, more complex validation might require regular expressions. You can modify the client script to use a regular expression to match a specific numeric format (e.g., allowing a country code and spaces).

  2. UI Policies: UI Policies can dynamically show or hide other elements depending on whether a field contains only numbers, creating dependent validation rules based on numeric entries.


Key Takeaways and Next Steps


Ensuring numeric input in your ServiceNow service catalog variables is crucial for data accuracy and workflow efficiency. Modern ServiceNow versions offer easier methods using validation Regex features, which removes the needs for scripting and enhances the efficiency and maintainability. For those on older version using the script provides control and customization option, offering robust validation options.


Actionable Steps


  1. Identify variables in your ServiceNow service catalog that require numeric input.

  2. Implement one of the solutions described above (Validation Regex, or Client Script).

  3. Test your implementation thoroughly to ensure that the validation works as expected.

  4. Monitor your ServiceNow instance for any data quality issues and adjust your validation rules as needed.

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