mwaples@optusnet.com.au writes:
> 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 ?
Sure, use a regexp pattern match, eg
regression=# create table fooey (f1 text check (f1 ~ '^[A-Za-z0-9]*$'));
CREATE
regression=# insert into fooey values('zzz33');
INSERT 145186 1
regression=# insert into fooey values('zzz 33');
ERROR: ExecAppend: rejected due to CHECK constraint fooey_f1
regression=#
The pattern match operators are not very well documented in the 7.0
docs, but see
http://www.postgresql.org/devel-corner/docs/postgres/functions-matching.htm
regards, tom lane