[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4676
  • Last Modified:

Alpha numeric validation on a SQL field

I have a requirement to validate a field coming as input parameter to A Stored proc. this field can be only ALPHA Numeric.  Ho w I can implement this .

1 ) Is there is any ALPHA numeric Data type in SQL server 2005
2) Is there is a function which can return False or True based on Aphanumeric validation. such that I can call my function from SP it does Alphanumericr validation
 Any sql code snippete will be of great help

Thanks a lot for all your help
0
snidenik
Asked:
snidenik
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>1 ) Is there is any ALPHA numeric Data type in SQL server 2005
VARCHAR, NVARCHAR

>2) Is there is a function which can return False or True based on Aphanumeric validation.
what kind of validation, more precisely?
0
 
snidenikAuthor Commented:
I am sorry for not being precise...what I am looking is for a function. which only returns  true if only below characters
A-Z, a-z, 0-9, _  

are passed as Stored procedure parameters and return FAil if any other character like (@, * ~,' etc ) are present in the passed input parameter
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you can use a simple LIKE in a CASE, like this:

declare @s varchar(10)
set @s = 'a_1'    --- put here any string to test....

select  case when @s like '%[^A-Z0-9_]%' then 0 else 1 end

will return 1 when valid according to the string(s), and 0 if not...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now