CakePHP Validation Regex

I have a quick question with a regular expression that I thought someone might know from the head. What will be the regular expression for CakePHP validation if I only want to specify the upper / lower alphabetic number, spaces, punctuation and quotation marks? This is what I have, but this:

 'rule' => array('custom', '/[a-z0-9\x20\x21\x2E\x3A\x3B\x3F\x2C\x27\x22]{0,600}/i'),

From what I get, a-z0-9 covers alphanumeric, but shouldn't \ xXX cover punctuation with sixth ASCII codes? And then {0,600] means the length of 0-600 characters, and I mean the top and bottom. What am I missing?

For example: valid: this is a "valid text" that contains "and punctuation!

false: this is an obvious attempt to XSS

+3
source share
2 answers
^([\d\w\s?!\.;:,'"\/\[\]\(\)=\+-]*)$

? , .

preg_match('/^([\d\w\s?!\.;:,'"\/\[\]\(\)=\+-]*)$/', $string);
+3

, , ASCII,

$input = "this is a \n string\n";
echo preg_match("/^[ -~]{0,600}$/", $input);  // output is 0 (false)
$input = "this is a string";
echo preg_match("/^[ -~]{0,600}$/", $input);  // output is 1 (true)

, ASCII, . , ~, . 0-600 , $

+1

All Articles