[MSSQL]Block certain characters

Joined
Oct 1, 2007
Messages
433
Reaction score
0
Hello, I have a MSSQL database. I have a table in there that has a column that I do not want to allow the use of
Quote:
[

or
Quote:
]

When the database is queried to insert something into this table involving that character ([ or ]), I want it to be not allowed, give an error, or something as long as it does not create the section in the column with the [ or ].
Thanks for the help.

I am also ok if the only thing I can do is allow text only, or allow text and numbers only.
 
Its for a game.. lets say players log in and create a character, thats when I want to block those [ ]

Someone on Devshed told me an example

Code:
create table check_test 
(
  data_value varchar(100) 
    check (charindex('[', data_value) = 0 and charindex(']', data_value) = 0)
)

But I'm unable to understand how to apply it to a current table.
 
But I'm unable to understand how to apply it to a current table.
It wouldn't be very fair towards the items already in the table to change the rules now, would it? But of course you can always create a new table with the rules and insert all from the old one.

What you're doing is definitely something I'd check before sending the input to the database.
 
Back