Skip to content
Advertisement

SQL CHECK() how to check if input is numeric value?

Hey how can I check if the input has 5 numbers? I tried everything like isnumeric/LIKE ‘%[0-9]%’ they all not working…

I tried the following but it doesn’t work.. please help

CREATE TABLE Code ( PIN TEXT NOT NULL, CHECK(LENGTH(title) = 5), CHECK(title LIKE '[0-9][0-9][0-9][0-9][0-9]'));

Advertisement

Answer

You can use GLOB operator:

CREATE TABLE Code ( 
  PIN TEXT NOT NULL,
  title TEXT,
  CHECK(title GLOB '[0-9][0-9][0-9][0-9][0-9]')
);

See the demo.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement