Subject Re: [firebird-php] Help! Validating Characters in Firebird
Author Thomas Beckmann
Luiz Duda schrieb:
> Good Afternoon to all.
>
> I am needing to validate one characters directly string(Only letters) in firebird, somebody has some tip?
> Example: string: LUIZ = valid
> string: LU1$'Z = invalid

How about these procedures:

CREATE PROCEDURE P_CHARSET_ONLY(
STRING VARCHAR(1024),
CHARSET VARCHAR(128))
RETURNS (
RESULT VARCHAR(1024))
AS
DECLARE VARIABLE C VARCHAR(1024);
DECLARE VARIABLE ALLOWED VARCHAR(1024);
begin
RESULT = '';
if (STRING is not null) then
while (STRING > '') do
begin
C = substring(STRING from 1 for 1);
select result from p_in_charset(:C, :CHARSET) into :ALLOWED;
if ('T' = ALLOWED) then
RESULT = RESULT || C;
STRING = substring(STRING from 2 for 255);
end
suspend;
end^

CREATE PROCEDURE P_IN_CHARSET(
LETTER CHAR(1),
CHARSET VARCHAR(128))
RETURNS (
RESULT CHAR(1))
AS
DECLARE VARIABLE C VARCHAR(1024);
begin
RESULT = 'F';
if (CHARSET is not null) then
while (CHARSET > '' and RESULT = 'F') do
begin
if (LETTER = substring(CHARSET from 1 for 1)) then RESULT = 'T';
CHARSET = substring(CHARSET from 2 for 128);
end
suspend;
end^


Use it like
select case result when 'LU1Z$Z' then 'valid' else 'invalid' end from
P_CHARSET_ONLY('LU1Z$Z',
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');

Questions welcome :-).
--
Thomas.Beckmann@...
Martens & Prahl EDV, Wielandstr. 14c, 23558 Lübeck
Telefon 0451-39904-525 • Telefax -520/-559