IP Validation : Variable Regex vs Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello Community,
I recently worked on IP address validation for monitoring catalog forms. Instead of using a Client Script, I found that Variable Validation Regex is a better low-code option. It reduces custom scripting, is easier to maintain, and aligns with ServiceNow’s no-code/low-code approach.
1- Create the regex record
Navigation - All - Service catalog - catalog variables - variable validation regex - new
Name - for example "IP address"
Validation message - for example "Enter valid IP address"
Active - True
Regular Expression - add your regex value
Regex Flag - None
Save
2- Link regex to the variable
Navigation - All - Service catalog - catalog Definations - Maintain Item - Open your record
Open Variable - Open your existing variable for IP address
Name - IP address
Type - Single line text(must for getting validation)
Related tab - Type Specification - Validation(or Regex) - Set your "variable validation regex" record i.e "IP address"
Benefits:
Instead of creating a Client Script, writing custom validation code, and configuring separate error messages, you can simply use Variable Validation Regex. This reduces custom scripting and makes the validation easier to configure and maintain.
Please mark this post as Helpful if you found it useful.
- 342 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Just to note that there are variable types "IP Address" and "Email" that do this OOTB. They do what you suggest (apply a regex test) ...but they do it on submit ("add to cart") rather than as you exit the field.
So the OOTB ones are simpler in that you pick that variable type and you're done but knowing how to build your own is great as then you can build validators for anything and you get the "immediate feedback" too.
