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- New

By ramesh_kondaparthy,

Alphanumeric and Special Character Validation
Function name: fn_ValidateString
Description : This function is used to validate whether the given string contains Alphanumeric character and some special character’s ‘@’ ,’(‘, ‘ )’, ‘_’, ‘-‘

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 1
Else 0

1) Select dbo.fn_ValidateString('asd(a3)3_3AAAXXX-3',0)
Return 0 – Failure
Because it contains special characters (, )

2) Select dbo.fn_ValidateString('asda333AAAXXX3',0)
Returns 1 – Success only alpha numerics

3) Select dbo.fn_ValidateString('asd(a3)3_3AAAXXX-3',1)
Return 1 – Success

4) Select dbo.fn_ValidateString('asd(a3)3_3AAAXXX-3%''^&',1)

Return 0 – Failure


Total article views: 858 | Views in the last 30 days: 5
Related Articles

Random 64 Characters alphanumeric String

Random 64 Characters alphanumeric String


Alphanumeric and Special Character Validation

Alphanumeric and Special Character Validation ========================================= /* Functi...


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.


Alphanumeric and Special Character Validation

Inspired in the script submited by ramesh_kondaparthy , this is a set oriented solution for the same...


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