Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Alphanumeric and Special Character Validation

By myoldhouse,

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

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

Total article views: 366 | Views in the last 30 days: 7
Related Articles

Random 64 Characters alphanumeric String

Random 64 Characters alphanumeric String


Extarcting string after and before a Character/Pattern

Finding characters/string before and after some character or pattern


Trim Non-Alpha characters from string

Trim Non-Alpha characters from string


ASCII Character Groups in String

Powerful function to find strings containing or excluding classes of ASCII characters.


Conversion failed when converting datetime from character string - Error....

Conversion failed when converting datetime from character string - Error


Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones