> -----Original Message-----
> From: Jim Lucas [mailto:[EMAIL PROTECTED]
> Sent: January 17, 2007 8:10 PM
> To: Jim Lucas
> Cc: Beauford; 'PHP'
> Subject: Re: [PHP] One last try at this!
>
> Jim Lucas wrote:
> > Beauford wrote:
> >> This is what I am trying to do, and for the most part it
> works, but
> >> it also may be causing some of my other problems.
> >>
> >> If $event contains invalid characters, I am returning a
> string that
> >> says "Invalid Characters" So $result now contains the
> value 'Invalid
> >> Characters'.
> >> Then $formerror['event'] = $result - is self explanatory.
> >>
> >> If there are no errors nothing is returned and $result
> should contain
> >> anything. But this doesn't always seem to be the case.
> This is one of
> >> the problems I am having.
> >>
> >> This is the code in a nutshell.
> >>
> >> if($result = ValidateString($event)) { $formerror['event']
> = $result;
> >> function ValidateString($string) {
> >>
> >> if(!preg_match("/^[-A-Za-z0-9_.' ]+$/", $string)) {
> >> return "Invalid Characters";
> >> }
> >>
> >> Thanks
> >>
> >>
> > In your regex you have a "." this will match anything
> >
> > try this:
> >
> > <plaintext><?php
> >
> > function ValidateString($string) {
> > if ( preg_match("/[^a-zA-Z0-9\_\.\' -]+/", $string) ) {
> > return "Invalid Characters";
> > }
> > return false;
> > }
> >
> > $formerror = array();
> forgot to say that all you need to do to get rid of the
> default values is remove the following two lines
>
> > $formerror['firstAttempt'] = 'first attempt';
> > $formerror['secondAttempt'] = 'second attempt';
> >
> > $event = "A-Z and a-z plus 0-9 and an '_' are allowed."; if ( (
> > $result = ValidateString($event) ) !== false ) {
> > $formerror['firstAttempt'] = $result; }
> >
> > $event = "But bad chars like [EMAIL PROTECTED] and %^&* are not
> allowed."; if ( (
> > $result = ValidateString($event) ) !== false ) {
> > $formerror['secondAttempt'] = $result; }
> >
> > var_dump($formerror);
> >
> > ?>
> >
> > Jim Lucas
> >
The regex itself was not really the problem, although I appreciate the help
on that, but I'm not sure I follow the rest of what your saying. I tried
your line below, and whether or not there were errors, an error was always
returned. So ABC or @#$ would give me the same result.
if ( ($result = ValidateString($event) ) !== false ) {
$formerror['firstAttempt'] = $result; }
Thanks
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php