Monday, September 10, 2007

Validate for allowed characters in a sting

-- Validate for allowed characters in a sting
-- If the sting contains even one character which is not in the list, returns 1 else 0
declare
@string varchar(20)
set @string ='abcd01234'
select case when @string like '%[^a-zA-Z0-9!@~#$\^&*()\_+-;:",.{}]%' escape '\' then 1 else 0 end

-- To check only alphacharacters in the sting ( a-z , A-Z)

declare @string varchar(20) s
et @string ='azAZ'
select case when @string like '%[^a-zA-Z]%' then 1 else 0 end

No comments: