Click here to Skip to main content
15,885,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
declare @test varchar(50)
set @test='sad@fd'
if @test LIKE '%[a-zA-Z0-9  ./,()?''+-]%'
print 'yes'
else
print 'no'

My above code giving yes result as it should give no as i am not allowing '@' in regular expression.Is there anything wrong.
My requirement is allow alpha numeric string with "./,()?''+-" this character allowed if string contains.
Posted
Updated 13-Mar-14 18:40pm
v2
Comments
Ankur\m/ 14-Mar-14 0:58am    
I haven't used regex in SQL but going by similar principles in .net I think you have a '%' in the start and end which stands for allow anything before/after your defined expression. You probably need to fix that.
vishal_h 14-Mar-14 1:09am    
Thanks,I want to handle this in store procedure where string is aplha numeric with specified list of special character allowed.what should i do.

LIKE does not support regular expressions. You need to use the full text index if you want to go beyond what LIKE supports ( which is not much ). In any case, using Full Text allows SQL to build an index, LIKE discards the use of indexes and slows down your queries.

Your other option, if you need regex support, is to use the CLR support to write a .NET method that uses regex.

It is generally good to read the documentation instead of making things up and hoping they will work :-)
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900