|
Posted by petersprc on 10/11/06 13:38
It could be an encoding issue. If your input string is utf8, try adding
the /u modifier to the pattern.
You could also try error_reporting(E_ALL) as a precaution. Could you
paste your whole function and the var_dump output of your input string?
Mark Woodward wrote:
> Hi petersprc,
>
> On Wed, 11 Oct 2006 05:55:43 -0700, petersprc wrote:
>
> > Try backslashing the single quote: $match = '/^[\'\w\.\-_?!, ]+$/';
>
> I've tried that but still seen as an illegal character??? Weird!
> (See first alternative match below).
>
> Could it be an encoding issue?
>
>
> >
> > In a single-quoted string, a literal single quote must be escaped with
> > a backslash. See here for string usage:
> >
> > http://us2.php.net/manual/en/language.types.string.php
> >
> > Mark Woodward wrote:
> >> Hi all,
> >>
> >> I'm trying to validate text in a HTML input field.
> >> How do I *allow* a single quote?
> >>
> >> // catch any nasty characters (eg !@#$%^&*()/\)
> >> $match = '/^['\w\.\-_?!, ]+$/';
> >> $valid_srch = preg_match($match, $res_description);
> >> if (!$valid_srch) {
> >> ...
> >> }
> >>
> >>
> >>
> >> for $match I've also tried:
> >>
> >> $match = '/^[\'\w\.\-_?!, ]+$/';
> >>
> >> $match = '/^["\w\.\-_?!, ]+$/';
> >>
> >> $match = "/^['\w\.\-_?!, ]+$/";
> >>
> >> $match = "/^[\'\w\.\-_?!, ]+$/";
> >>
> >> and numerous other strings but always ' is seen as an
> >> invalid character.
> >>
> >>
> >> thanks,
> >>
> >>
> >> --
> >> Mark
>
>
> cheers,
>
> --
> Mark
[Back to original message]
|