Inspired in the script submited by ramesh_kondaparthy , this is a set oriented solution for the same problem.
Parameters: 1) @InputString varchar(25)
Accepts the string, which we need to validate
2) @Type int
= 0 validate the string for only alphanumeric characters
i.e Allows characters between [A-Z] ,[a-z] and [0-9]
= 1 validate the string for alphanumeric and special characters - ‘@’ ,’(‘, ‘ )’, ‘_’, ‘-‘
Return type: int
If the passed string is valid, it returns 0
Else 1
Usage:
1) Select dbo.fn_ValidateString('asd(a3)3_3AAAXXX-3',0)
Return 1 – Failure
2) Select dbo.fn_ValidateString('asd(a3)3_3AAAXXX-3',1)
Return 0 – Success
2007-10-02 (first published: 2002-06-20)
15,451 reads