|
Posted by Raistlin Majere on June 20, 2008, 3:08 pm
Please log in for more thread options
// there is
define('VALID_MESSAGE', '/^[a-zA-Z0-9 ,.!?\n]$/');
// there is
function validate($variable, $name, $valid, $name2, $inornot)
// there is
if (!preg_match($valid, $variable)) {
$_SESSION["trying"]="The ".$name." is invalid!";
return false;
}
// it accepts
testtesttesttesttesttest
// it refuses
testtest
testtest
testtest
Why?
|
|
Posted by Raistlin Majere on June 20, 2008, 3:11 pm
Please log in for more thread options
// there is too
if (!validate($subject, "subject", VALID_SUBJECT, $subject2, "in")) {
header ("Location: create.php");
> // there is
>
> define('VALID_MESSAGE', '/^[a-zA-Z0-9 ,.!?\n]$/');
>
> // there is
>
> function validate($variable, $name, $valid, $name2, $inornot)
>
> // there is
>
> if (!preg_match($valid, $variable)) {
> =A0 =A0 =A0 =A0 $_SESSION["trying"]=3D"The ".$name." is invalid!";
> =A0 =A0 =A0 =A0 return false;
>
> }
>
> // it accepts
>
> testtesttesttesttesttest
>
> // it refuses
>
> testtest
> testtest
> testtest
>
> Why?
|
|
Posted by Rik Wasmus on June 20, 2008, 3:17 pm
Please log in for more thread options wrote:
> define('VALID_MESSAGE', '/^[a-zA-Z0-9 ,.!?\n]$/');
> // it accepts
> testtesttesttesttesttest
>
> // it refuses
> testtest
> testtest
> testtest
Most likely, because of \r.
An obvious solution would be:
define('VALID_MESSAGE','/^[a-z0-9,.!?\s]$/i');
Allthough I'd rather use a (mb_)strlen() & '/^[a-z0-9,.!?\s]+$/i' for some
reason. I have no idea wether that's more efficient or not, or even why I
prefer it...
--
Rik Wasmus
...spamrun finished
|
|
Posted by Raistlin Majere on June 20, 2008, 3:43 pm
Please log in for more thread options it still says the message is invalid
=A0
> wrote:
>
> > define('VALID_MESSAGE', '/^[a-zA-Z0-9 ,.!?\n]$/');
> > // it accepts
> > testtesttesttesttesttest
>
> > // it refuses
> > testtest
> > testtest
> > testtest
>
> Most likely, because of \r.
> An obvious solution would be:
> define('VALID_MESSAGE','/^[a-z0-9,.!?\s]$/i');
>
> Allthough I'd rather use a (mb_)strlen() & '/^[a-z0-9,.!?\s]+$/i' for som=
e =A0
> reason. I have no idea wether that's more efficient or not, or even why I=
=A0
> prefer it...
> --
> Rik Wasmus
> ...spamrun finished
|
|
Posted by Rik Wasmus on June 20, 2008, 3:50 pm
Please log in for more thread options wrote:
>> On Fri, 20 Jun 2008 21:08:24 +0200, Raistlin Majere
>> wrote:
>>
>> > define('VALID_MESSAGE', '/^[a-zA-Z0-9 ,.!?\n]$/');
>> > // it accepts
>> > testtesttesttesttesttest
>>
>> > // it refuses
>> > testtest
>> > testtest
>> > testtest
>>
>> Most likely, because of \r.
>> An obvious solution would be:
>> define('VALID_MESSAGE','/^[a-z0-9,.!?\s]$/i');
Please don't toppost.
> it still says the message is invalid
Not here it doesn't:
<?php
$variable = 'tasdtasd
asdasd
asdasd
asdasd';
$valid = '/^[a-z0-9,.!?\s]$/';
echo preg_match($valid, $variable) ? 'valid' : 'invalid';
?>
Outputs:valid
If you made sure the right regex & variable arrived at your function, i'd
be interested in this output:
for($i = 0;$i < strlen($variable) ; $i++){
echo $variable[$i].'='.ord($variable[$i])."\n";
}
--
Rik Wasmus
|
| Similar Threads | Posted | | I can not match "&" - regexp | April 26, 2007, 3:56 am |
| Simple text file reading codes NOT working | October 17, 2005, 11:20 am |
| regexp: match negation | May 9, 2006, 11:09 pm |
| RegExp for removing text between parenthesis | February 4, 2005, 10:27 am |
| Regexp - matching text not containing certain count of certain characters | April 8, 2006, 11:04 am |
| Cannot get this one correct and working, though simple! | December 29, 2005, 10:31 pm |
| simple eregi not working (PEBCAK) | December 4, 2004, 7:19 pm |
| simple text editor | December 19, 2004, 2:29 am |
| PHP simple plain text menu, suggestions ? | November 4, 2005, 11:40 am |
| Simple Challenge - Working with image coordinates and dynamic linking. | December 19, 2004, 11:36 am |
|