How to build a regex for an IP Addres Range?

Jesus Nava
Tera Guru

Hello experts please I need your help, how can a regex to accept an IP range be built? for example:

34.3.4.4 - 34.3.4.5

I have this regex from 

https://community.servicenow.com/community?id=community_question&sys_id=0cf3a62ddbb8a010fa192183ca96198e

^(?=.*?[1-9])[0-9()-]+$

but it is not working as I need it, I need that the user can add and IP address with the character - so as to add a range, how can that be done?

Thank you

1 ACCEPTED SOLUTION

Muhammad Khan
Mega Sage
Mega Sage

Hi Jesus,

 

Try this in variable validation regex

^[0-9]+.[0-9]+.[0-9]+.[0-9]+ \- [0-9]+.[0-9]+.[0-9]+.[0-9]+$

View solution in original post

16 REPLIES 16

Hello Muhammad, yes it is an IP address, and if I add the OOB regex for IP address validation in the variable, it works for one IP address biut not for a range, if I add the character ( - ) the alert says "incorrect IP address"

Thanks

As per my knowledge, Variable Validation Regex is not available for IP Address type variable, So are you using client script for validation ?

Hello Muhhamad, I still get the validation error

Regards

I just ran a test using this code and it is accepting this with no issue, thank you!!

 

You should not use that regex. It would accept input of "9999999 - 123456789" which is very clearly not an IP address range.