Re: regular expression question
От | Alvaro Herrera |
---|---|
Тема | Re: regular expression question |
Дата | |
Msg-id | 20030605060514.GH3268@dcc.uchile.cl обсуждение исходный текст |
Ответ на | regular expression question (Joel Rodrigues <borgempath@Phreaker.net>) |
Ответы |
Re: regular expression question
|
Список | pgsql-general |
On Thu, Jun 05, 2003 at 12:10:18AM +0530, Joel Rodrigues wrote: > Hi, > I'm trying to write a check on a column restricting the data to > numerals from 0-9, commas, dashes '-' and single spaces. To allow the > entry of something like "134-140, 310-312". > > I seem to have got everything but the single spaces. > > '^[0-9|,-]{0,10}$' I don't think you can do what you want with a single regular expression. You'll probably need to use multiple constraints: one to check for the valid characters and the maximum length, and another to check that there aren't two spaces together, regression=# create table dos (a text, constraint dos_a_uno check (a ~ '^[a-z ]{0,10}$'), constraint dos_a_dos check (a !~ ' ')); CREATE TABLE regression=# insert into dos values ('aaba'); INSERT 17091 1 regression=# insert into dos values ('aaba '); INSERT 17092 1 regression=# insert into dos values ('aaba '); ERROR: ExecInsert: rejected due to CHECK constraint "dos_a_dos" on "dos" -- Alvaro Herrera (<alvherre[a]dcc.uchile.cl>) "En las profundidades de nuestro inconsciente hay una obsesiva necesidad de un universo lógico y coherente. Pero el universo real se halla siempre un paso más allá de la lógica" (Irulan)
В списке pgsql-general по дате отправления: