|
Posted by Pedro Graca on 10/29/06 23:17
cendrizzi wrote:
> So I start with this:
> /<(input|select|textarea)[^>]*name\s*\=\s*\"[_a-zA-Z0-9\s]*\"[^>]*>/
You'd better not use regular expressions to validate HTML.
The following line is perfectly valid HTML (I think in any version)
<input type="text" name="x><y" id="xy">
> but need to modify it so it only matches if it has '{' characters in
> the name but to not match if it does not.
>
> So this would not match:
> <input name="test">
>
> But this would match:
> <input name="test{0}">
Get the name. Verify it has '{' and '}' (in that order and once only?)
<?php
$name = get_name('<input name="test{0}">'); // 'test{0}'
if (name_is_valid($name)) {
// whatever
}
function get_name($html) {
return 'test{0}'; // sorry!
}
function name_is_valid($name) {
if (($p1 = strpos($name, '{')) === false) return false;
if (strpos($name, '{', $p1+1) !== false) return false;
if (($p2 = strpos($name, '}')) === false) return false;
if (strpos($name, '}', $p2+1) !== false) return false;
return $p1 < $p2;
}
?>
--
I (almost) never check the dodgeit address.
If you *really* need to mail me, use the address in the Reply-To
header with a message in *plain* *text* *without* *attachments*.
Navigation:
[Reply to this message]
|