Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Pattern Matching

Author  Topic 

adweigert
Starting Member

22 Posts

Posted - 2003-09-30 : 16:07:38
Forgive me, I'm very frustrated by this and hoping someone here can help me. Basically I want to formulate a pattern that can be used to make sure that only valid characters can be put into a user name.

SELECT 1 WHERE NOT ('user@domain' LIKE '[^a-zA-Z0-9]')

returns the value 1 ... even though @ is not a valid character...

I must be missing something, but this should work ... now if I try to check against a LIKE where teh pattern is a string of valid character sets ... it works correctly ...

help :) please :D

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-09-30 : 16:54:23
you are only checking the first character of 'user@domain'.

- Jeff
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-09-30 : 16:58:38
UDF...UDF...UDF...UDF....

I think you'll need a User Defined Function....

And spin through the string for LEN(@string)



Brett

8-)

SELECT @@POST FROM Brain ORDER BY NewId()

That's correct! It's an AlphaNumeric!
Go to Top of Page

airjrdn
Starting Member

35 Posts

Posted - 2003-09-30 : 17:11:07
Assuming I understand you correctly, you want to ensure that a particular list of characters are nowhere inside a variable's value prior to performing an insert, correct? Ie; to ensure you don't save an invalid email address in this case.

If that's the case, I'd suspect you'll have to create a table of invalid characters, and cycle through every letter of the variable to see if that letter is in your table of invalid characters. As soon as one is found, cease the search and exit your looping structure indicating that you found a "bad" character.

Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2003-09-30 : 17:33:44
I think you want

SELECT 1 WHERE patindex('%[^a-zA-Z0-9]%','user@domain') <> 0

That will return 1 if there are any chars not in a-zA-Z0-9

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

adweigert
Starting Member

22 Posts

Posted - 2003-09-30 : 19:23:31
Told you it was simple, just not getting it ... was thinking in RegEx land with IsMatch ... :-p

How about this...

WHERE Name LIKE REPLICATE('[a-zA-Z0-9]', LEN(Name))
Go to Top of Page
   

- Advertisement -