I want to create a rule to restrict special characters to be entered into a column. I have tried the following. But it didnt work.
CREATE RULE rule_spchar
AS
@ma
It's important to remember Microsoft's plans for the features you're using or intending to use. CREATE RULE is a deprecated feature that won't be around for long. Consider using CHECK CONSTRAINT
instead.
Also, since the character exclusion class doesn't actually operate like a RegEx, trying to exclude brackets []
is impossible this way without multiple calls to LIKE
. So collating to an accent-insensitive collation and using an alphanumeric inclusive filter will be more successful. More work required for non-latin alphabets.
M.Ali's NOT LIKE '%[^A-Z0-9 ]%'
Should serve well.