1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| CREATE OR REPLACE FUNCTION ikt_ip_address_check2(character varying)
RETURNS boolean AS
$BODY$
DECLARE
a character varying;
BEGIN
--Verification de la presence de points.
IF (contains($1,'.') return false)
THEN
Raise Exception '|WRONG_IP_ADRESS|%|is a wrong ip adress/point missed by the tiped ip_address',$1;
ELSIF(position('.' in $1).length > 3)
THEN
Raise Exception '|WRONG_IP_ADRESS|%|is a wrong ip adress/the tiped ip_address must have 3 points',$1;
END IF;
--Verification de la longueur de la chaine.
IF (length($1) > 15)
THEN
Raise Exception '|WRONG_IP_ADRESS|%|is a wrong ip adress/the tiped ip_address is to long ',$1;
END IF;
--Expression regulaire pour le format d´une adresse ip.
IF ((length($1)!=0) AND ($1 !~ '(^[0-9]{1,3}\.\[0-9]{1,3}\.\[0-9]{1,3}\.\[0-9]{1,3}$)'))
THEN
Raise Exception '|WRONG_IP_ADRESS|%|is a wrong ip adress/The ip_address must have only numbers ',$1;
END IF;
RETURN true;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100; |
Partager