How to detect if a string contains special characters like #,$,^,&,*,@,! etc (non-alphanumeric characters) in SQL server 2005?
new Regex(“[^A-Za-z0-9]”) the pattern is used to check whether the string contains special characters or not. IsMatch() function checks the string and returns True if the string contains a special character. int. TryParse(str, out int n) the method returns True if the string contains the number(s).
Assuming SQL Server:
e.g. if you class special characters as anything NOT alphanumeric:
DECLARE @MyString VARCHAR(100) SET @MyString = 'adgkjb$' IF (@MyString LIKE '%[^a-zA-Z0-9]%') PRINT 'Contains "special" characters' ELSE PRINT 'Does not contain "special" characters'
Just add to other characters you don't class as special, inside the square brackets
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With