Home All Groups Group Topic Archive Search About
Author
30 Jun 2005 2:15 PM
Kathy
Hi All,

I need to know how to do the following
I need to know how to validate an IP address
i.e. if you have an ip of 10.1 (not valid)
if you have ip of 10.1.1.1 (then valid)

How does one do this in SQL

Thanks for the help
Kathryn

Author
30 Jun 2005 2:36 PM
JT
It may not be bullet proof, but the following first verifies that the IP has
four dots followed or preceeded by at least 1 character. It then verifies
that all the characters in the IP are either digits or dots.

if '10.1.1.1' like '%_._%._%._%' and not '10.1.1.1' like '%[^0123456789.]%'
print 'Yes'
else
print 'No'


Show quote
"Kathy" <r**@roo.com> wrote in message
news:CbydneWBuO8-Y17fRVn-3A@is.co.za...
> Hi All,
>
> I need to know how to do the following
> I need to know how to validate an IP address
> i.e. if you have an ip of 10.1 (not valid)
> if you have ip of 10.1.1.1 (then valid)
>
> How does one do this in SQL
>
> Thanks for the help
> Kathryn
>
>
Author
30 Jun 2005 2:50 PM
Kathy
You are an absolute GENIUS - thank you


Show quote
"JT" <some***@microsoft.com> wrote in message
news:%23pFXjFYfFHA.2152@TK2MSFTNGP14.phx.gbl...
> It may not be bullet proof, but the following first verifies that the IP
> has
> four dots followed or preceeded by at least 1 character. It then verifies
> that all the characters in the IP are either digits or dots.
>
> if '10.1.1.1' like '%_._%._%._%' and not '10.1.1.1' like
> '%[^0123456789.]%'
> print 'Yes'
> else
> print 'No'
>
>
> "Kathy" <r**@roo.com> wrote in message
> news:CbydneWBuO8-Y17fRVn-3A@is.co.za...
>> Hi All,
>>
>> I need to know how to do the following
>> I need to know how to validate an IP address
>> i.e. if you have an ip of 10.1 (not valid)
>> if you have ip of 10.1.1.1 (then valid)
>>
>> How does one do this in SQL
>>
>> Thanks for the help
>> Kathryn
>>
>>
>
>
Author
30 Jun 2005 3:25 PM
Itzik Ben-Gan
Here you go:

SELECT CASE WHEN
    -- 3 periods and no empty octets
    @ip LIKE '%_.%_.%_.%_'
  AND
    -- not 4 periods or more
    @ip NOT LIKE '%.%.%.%.%'
  AND
    -- no characters other than digits and periods
    @ip NOT LIKE '%[^0-9.]%'
  AND
    -- not more than 3 digits per octet
    @ip NOT LIKE '%[0-9][0-9][0-9][0-9]%'
  AND
    -- NOT 300 - 999
    @ip NOT LIKE '%[3-9][0-9][0-9]%'
  AND
    -- NOT 260 - 299
    @ip NOT LIKE '%2[6-9][0-9]%'
  AND
    -- NOT 256 - 259
    @ip NOT LIKE '%25[6-9]%'
  THEN 'Valid' ELSE 'Invalid' END

--
BG, SQL Server MVP
www.SolidQualityLearning.com


Show quote
"Kathy" <r**@roo.com> wrote in message
news:CbydneWBuO8-Y17fRVn-3A@is.co.za...
> Hi All,
>
> I need to know how to do the following
> I need to know how to validate an IP address
> i.e. if you have an ip of 10.1 (not valid)
> if you have ip of 10.1.1.1 (then valid)
>
> How does one do this in SQL
>
> Thanks for the help
> Kathryn
>
Author
1 Jul 2005 5:45 AM
Kathy
Aaah another genius in our midst

Thanks alot Itzik - brilliant - gonna keep this for future reference

Show quote
"Itzik Ben-Gan" <it***@REMOVETHIS.SolidQualityLearning.com> wrote in message
news:ugDqYfYfFHA.1472@TK2MSFTNGP12.phx.gbl...
> Here you go:
>
> SELECT CASE WHEN
>    -- 3 periods and no empty octets
>    @ip LIKE '%_.%_.%_.%_'
>  AND
>    -- not 4 periods or more
>    @ip NOT LIKE '%.%.%.%.%'
>  AND
>    -- no characters other than digits and periods
>    @ip NOT LIKE '%[^0-9.]%'
>  AND
>    -- not more than 3 digits per octet
>    @ip NOT LIKE '%[0-9][0-9][0-9][0-9]%'
>  AND
>    -- NOT 300 - 999
>    @ip NOT LIKE '%[3-9][0-9][0-9]%'
>  AND
>    -- NOT 260 - 299
>    @ip NOT LIKE '%2[6-9][0-9]%'
>  AND
>    -- NOT 256 - 259
>    @ip NOT LIKE '%25[6-9]%'
>  THEN 'Valid' ELSE 'Invalid' END
>
> --
> BG, SQL Server MVP
> www.SolidQualityLearning.com
>
>
> "Kathy" <r**@roo.com> wrote in message
> news:CbydneWBuO8-Y17fRVn-3A@is.co.za...
>> Hi All,
>>
>> I need to know how to do the following
>> I need to know how to validate an IP address
>> i.e. if you have an ip of 10.1 (not valid)
>> if you have ip of 10.1.1.1 (then valid)
>>
>> How does one do this in SQL
>>
>> Thanks for the help
>> Kathryn
>>
>
>
Author
1 Jul 2005 4:16 PM
JT
Google keeps a copy of everything we say and do on the web, warts and all.

Show quote
"Kathy" <r**@roo.com> wrote in message
news:c8adnY77SczDRVnfRVn-3w@is.co.za...
> Aaah another genius in our midst
>
> Thanks alot Itzik - brilliant - gonna keep this for future reference
>
> "Itzik Ben-Gan" <it***@REMOVETHIS.SolidQualityLearning.com> wrote in
message
> news:ugDqYfYfFHA.1472@TK2MSFTNGP12.phx.gbl...
> > Here you go:
> >
> > SELECT CASE WHEN
> >    -- 3 periods and no empty octets
> >    @ip LIKE '%_.%_.%_.%_'
> >  AND
> >    -- not 4 periods or more
> >    @ip NOT LIKE '%.%.%.%.%'
> >  AND
> >    -- no characters other than digits and periods
> >    @ip NOT LIKE '%[^0-9.]%'
> >  AND
> >    -- not more than 3 digits per octet
> >    @ip NOT LIKE '%[0-9][0-9][0-9][0-9]%'
> >  AND
> >    -- NOT 300 - 999
> >    @ip NOT LIKE '%[3-9][0-9][0-9]%'
> >  AND
> >    -- NOT 260 - 299
> >    @ip NOT LIKE '%2[6-9][0-9]%'
> >  AND
> >    -- NOT 256 - 259
> >    @ip NOT LIKE '%25[6-9]%'
> >  THEN 'Valid' ELSE 'Invalid' END
> >
> > --
> > BG, SQL Server MVP
> > www.SolidQualityLearning.com
> >
> >
> > "Kathy" <r**@roo.com> wrote in message
> > news:CbydneWBuO8-Y17fRVn-3A@is.co.za...
> >> Hi All,
> >>
> >> I need to know how to do the following
> >> I need to know how to validate an IP address
> >> i.e. if you have an ip of 10.1 (not valid)
> >> if you have ip of 10.1.1.1 (then valid)
> >>
> >> How does one do this in SQL
> >>
> >> Thanks for the help
> >> Kathryn
> >>
> >
> >
>
>

AddThis Social Bookmark Button