Re: Validating Data

From: Mladen Gogala <gogala.mladen_at_gmail.com>
Date: Sun, 26 Feb 2012 00:17:10 +0000 (UTC)
Message-ID: <pan.2012.02.26.00.17.10_at_gmail.com>



On Sun, 26 Feb 2012 00:39:11 +0100, Robert Klemme wrote:
>> With all due respect, why would you use a database for such thing?

>
> The most prominent reason is that general rule to check inputs when they
> enter a system.

This looks like a web application as the original poster has mentioned PHP. Web server looks like the most logical place to prevent an undesired data format from being entered into the system. Of course, there is an advantage of doing it in the database, because the input checking is centralized and you don't have to worry about that in the applications. Oracle also support POSIX character classes in its regular expressions implementation:

SQL> select regexp_count('HAL 9000','[[:digit:]]',1) from dual;

REGEXP_COUNT('HAL9000','[[:DIGIT:]]',1)


                                      4

Elapsed: 00:00:00.00
SQL> select regexp_count('HAL 9000','[[:print:]]',1) from dual;

REGEXP_COUNT('HAL9000','[[:PRINT:]]',1)


                                      8

Elapsed: 00:00:00.01
SQL> select regexp_count('HAL 9000','[^[:print:]]',1) from dual;

REGEXP_COUNT('HAL9000','[^[:PRINT:]]',1)


                                       0

Elapsed: 00:00:00.01
SQL> select regexp_count('HAL 9000','[^[:digit:]]',1) from dual;

REGEXP_COUNT('HAL9000','[^[:DIGIT:]]',1)


                                       4

Elapsed: 00:00:00.00

However, having in mind how lightweight things are, when done through PHP I would probably do it in PHP. Maintaining a simple filter on the data, to prevent non-printable characters in the certain fields should not be a problem, either way.

-- 
http://mgogala.byethost5.com
Received on Sat Feb 25 2012 - 18:17:10 CST

Original text of this message