Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

IP URL regex validation

Amit Dey1
Tera Contributor

Hi , I have a requirement to validate IP URL and also anything after it , so I made this regex - ^(http[s]?:\/\/){0,1}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])(.*)      , but this regex is not checking the last number part is 255+ or not I mean this regex is validating this IP URL also =  https://172.29.219.330 , here see the last part is 330 still it is validating , please help me in this matter 

1 ACCEPTED SOLUTION

If user can add anything, then use below regex.

^(http[s]?:\/\/){0,1}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])(\/.*)?$

View solution in original post

3 REPLIES 3

Muhammad Khan
Mega Sage

It is because of (.*) at the end. Remove that and try. It should look like below.

^(http[s]?:\/\/){0,1}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])$

hi @Muhammad Khan but then I have to add anything after that part also like this https://172.29.219.33/(string)

so I mean after IP part user can add anything , but then it was not  checking  last part is 255+ or not 

If user can add anything, then use below regex.

^(http[s]?:\/\/){0,1}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])(\/.*)?$