On Mon, 1 Jan 2001 mwaples@optusnet.com.au wrote:
> I have table users with a varchar field user_name,
> Id like to restrict this to just alphanumeric characters
> can I do this with a check constraint ?
> or do I need to use a tigger and function ?
Use a regular expression in your check constraint:
create table reg_test (
id integer primary key,
descr varchar(20),
check (descr ~* '^[A-Z0-9]*$')
);
insert into reg_test values (1, 'data\&');
ERROR: ExecAppend: rejected due to CHECK constraint $1
-- Brett
http://www.chapelperilous.net/~bmccoy/
---------------------------------------------------------------------------
Feeling amorous, she looked under the sheets and cried, "Oh, no,
it's Microsoft!"