cancel
Showing results for 
Search instead for 
Did you mean: 

validate IP Address using SIMILAR TO

Baron
Participant
0 Kudos
650

what is the best way to validate a string against IP Address?

I tried using this, it works.

select 'is valid ip address' where '192.168.0.11' similar to '[0-9]+.[0-9]+.[0-9]+.[0-9]+'

But I have problem with this

select 'is valid ip address' where '192.16845444.0.11' similar to '[0-9]+.[0-9]+.[0-9]+.[0-9]+'
View Entire Topic
VolkerBarth
Contributor

Here's an REGEXP sample for IP addresses from the docs – I have not tested it myself:

((2(5[0-5]|[0-4][0-9])|1([0-9][0-9])|([1-9][0-9])|[0-9])\\.){3}(2(5[0-5]|[0-4][0-9])|1([0-9][0-9])|([1-9][0-9])|[0-9])

You may also check general regex samples for IP addresses like these, just make sure the syntax is also supported by SQL Anywhere.

Baron
Participant
0 Kudos

thanks for the answer, actually it is not so simple having that the range should be between 0-255, so my approach above is not yet correct.