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

Yousaf
Giga Sage

Hi,

Try this please.

^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$

 

Example

Accept:

127.0.0.1
192.168.1.1
192.168.1.255
255.255.255.255
0.0.0.0
1.1.1.01

Reject:

30.168.1.255.1
127.1
192.168.1.256
-1.2.3.4
1.1.1.1.
3...3




Mark Correct or Helpful if it helps.


***Mark Correct or Helpful if it helps.***

Hello Yousaf, I still get an error

find_real_file.png

here is what I added in the Regex

find_real_file.png

am I doing something wrong?

Thank you!

Oo Yes that was for IP address not Ip range.

Glad you found the answer.


***Mark Correct or Helpful if it helps.***

Thank you Yousaf for your help!!