Validating string format using sql server -
check if string following correct format or not. correct format follows:
2 upper case letters; 2 digits; 1 30 characters alpha-numerical (case insensitive) e.g. gb29rbos60161331926819, gb29rbos60161331926819a, gb29rbos60161331926819b1
so far have got...
declare @accountnumber varchar(1000) = 'gb99aerf12fdg8aerf12fdg8aerf12fdg8' select case when @accountnumber not '[a-z][a-z][0-9][0-9][0-9a-za-z]{30}$' 'error' else null end
first, structure assumes case sensitive collation. second, sql server doesn't recognize {}
or $
, have repeat pattern. however, want 30 characters, splitting pieces apart best solution:
select (case when len(@accountnumber) not between 5 , 34 or @accountnumber not '[a-z][a-z][0-9][0-9]%' or right(@accountnumber, 34) '%[^a-za-z0-9]%' 'error' end)
Comments
Post a Comment