SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 check Alphanumeric string
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

pushp82
Yak Posting Veteran

68 Posts

Posted - 07/24/2012 :  05:40:32  Show Profile  Reply with Quote
Hi,

I need to check a string in procedure if that is alphanumeric or not
means:
123aaa : Accepted
aaaaaa : not accepted
123123 : not accepted
how to fulfill this condition?
No special character allowed also.

Please help!
Pushkar

Edited by - pushp82 on 07/24/2012 05:53:05

Transact Charlie
Flowing Fount of Yak Knowledge

United Kingdom
3448 Posts

Posted - 07/24/2012 :  05:43:32  Show Profile  Visit Transact Charlie's Homepage  Reply with Quote
try this?

BEGIN TRAN

DECLARE @sample TABLE (
	[value] VARCHAR(MAX)
	)
INSERT @sample ([value])
VALUES ('123aaa')
	, ('aaaaaa')
	, ('123123')

SELECT * FROM @sample
WHERE
	[value] LIKE '%[a-Z]%'
	AND [value] LIKE '%[0-9]%'
	
ROLLBACK


Transact Charlie
Msg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
http://nosqlsolution.blogspot.co.uk/
Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8529 Posts

Posted - 07/24/2012 :  05:44:30  Show Profile  Visit webfred's Homepage  Reply with Quote
col like '%[0-9]%' AND col like '%[^0-9]%'



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22469 Posts

Posted - 07/24/2012 :  06:05:28  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
quote:
Originally posted by webfred

col like '%[0-9]%' AND col like '%[^0-9]%'



No, you're never too old to Yak'n'Roll if you're too young to die.


May not be accurate for data like 123#$7

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

pushp82
Yak Posting Veteran

68 Posts

Posted - 07/24/2012 :  06:27:42  Show Profile  Reply with Quote
I just added

NOT LIKE '%[!@#$%^&*()_+=-.":;><,/?\|]%'


So the statement is as below

IF(@string LIKE '%[^a-z]%' AND @string LIKE '%[^0-9]%' AND @string NOT LIKE '%[!@#$%^&*()_+=-.":;><,/?\|]%')

thanks for the quick responce guys, made my days

Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22469 Posts

Posted - 07/24/2012 :  06:43:33  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Have you tried TC's method that would be simple

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8529 Posts

Posted - 07/24/2012 :  06:47:11  Show Profile  Visit webfred's Homepage  Reply with Quote
quote:
Originally posted by madhivanan

quote:
Originally posted by webfred

col like '%[0-9]%' AND col like '%[^0-9]%'



No, you're never too old to Yak'n'Roll if you're too young to die.


May not be accurate for data like 123#$7

Madhivanan

Failing to plan is Planning to fail


I thought EXACTLY this is accurate


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Transact Charlie
Flowing Fount of Yak Knowledge

United Kingdom
3448 Posts

Posted - 07/24/2012 :  07:00:23  Show Profile  Visit Transact Charlie's Homepage  Reply with Quote
I think OP edited post to include a requirement not to include special characters.

This then is probably the nicest way of doing it

DECLARE @sample TABLE (
	[value] VARCHAR(MAX)
	)
INSERT @sample ([value])
VALUES ('123aaa')
	, ('aaaaaa')
	, ('123123')
	, ('asdsad"£"!3sad')
	, ('a+3')

SELECT * FROM @sample
WHERE
	[value] LIKE '%[a-Z]%'
	AND [value] LIKE '%[0-9]%'
	AND [value] NOT LIKE '%[^0-Z]%'


Transact Charlie
Msg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
http://nosqlsolution.blogspot.co.uk/
Go to Top of Page

pushp82
Yak Posting Veteran

68 Posts

Posted - 07/24/2012 :  07:39:18  Show Profile  Reply with Quote
you were actually perfect TC thanks for the logic....

quote:
Originally posted by Transact Charlie

I think OP edited post to include a requirement not to include special characters.

This then is probably the nicest way of doing it

DECLARE @sample TABLE (
	[value] VARCHAR(MAX)
	)
INSERT @sample ([value])
VALUES ('123aaa')
	, ('aaaaaa')
	, ('123123')
	, ('asdsad"£"!3sad')
	, ('a+3')

SELECT * FROM @sample
WHERE
	[value] LIKE '%[a-Z]%'
	AND [value] LIKE '%[0-9]%'
	AND [value] NOT LIKE '%[^0-Z]%'


Transact Charlie
Msg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
http://nosqlsolution.blogspot.co.uk/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000