2018-06-12 12:38 GMT+02:00 Clemens Ladisch <[email protected]>:

> Cecil Westerhof wrote:
> > I want to create a field that only has values that consist of letters,
> > numbers end '-'. So no spaces, quotes or special characters like: '@%$!'.
> > What is the best way to write this check constraint?
>
> The GLOB operator has inverted character classes.  So the field is valid
> if its value does not contain any character that is not in the valid list:
>
> CREATE TABLE [] (
>   Field  CHECK(Field NOT GLOB '*[^0-9A-Za-z-]*')
> );
>

​Thanks, seems to work. The field is not allowed to be NULL or empty, so I
use:
CREATE TABLE pipManual (
    package   TEXT NOT NULL,

    CHECK(package != ''),
    CHECK(package NOT GLOB '*[^0-9A-Za-z-]*')
);
​

-- 
Cecil Westerhof
_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to