views:

41

answers:

2

How to restrict the length? Like 12345.789.22.7890 is invalid because the IP ranges from 0-255

Kindly help me

A: 

Why not store the IP address as 4 256-bit elements (Byte type) along with a string repr? Sure, it sort of wastes space, but it allows you to write simpler queries, does not it?

Hamish Grubijan
A: 

How to restrict the length? Like 12345.789.22.7890 is invalid because the IP ranges from 0-255

Even if you break up the IP into it's respective octets, validating based solely on length of string will still produce false positives because any integer over 250 is three characters long.

The most validation that can be performed on an IP address without the subnet would be to use:

LIKE [1-250].[0-250].[0-250].[0-250]

...assuming submission as a single string (which I would consider using a CHECK constraint to enforce).

References:

OMG Ponies