Re: I lied, another question / problem
| From: | Frank Arensmeier | Date: | Tue, 16 Jan 2007 09:17:55 +0000 |
| Subject: | Re: I lied, another question / problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-247136@lists.php.net to get a copy of this message | ||
I believe that only two things could be messing up your validation:
a) input data
b) your function
a) Do a var_dump on your input data. Is there any white space characters or anything else that do not belong there in the string?
b) Rewrite your function/rethink what you are doing. You said that your function should match letters from a to Z and some special characters like ' - _ .
Try this regex:
^(\w+\s?[\'\-\_\.]?)+$
I would write the function as follows:
function invalidchar ( $input )
{
if ( preg_match ( "^(\w+\s?[\'\-\_\.]?)+$", $input ) ) { // string matches against the pattern, everything is ok
return $input;
} else {
return false;
}
}
if ( invalidchar ( $my_string ) == false ) {
// do some stuff
} else {
echo "You passed the test";
}
// untested
// frank
16 jan 2007 kl. 04.47 skrev Beauford:
My apologies, but I am just so frustrated right now. It seems my function doesn't work either (if that's even the problem, which at this time I just don't know). Somehow my variable is still getting a value, and I have no idea how. Even if I don't return anything it still gets a value. Basically this has just broken my whole site. If anyone can figure this out let me know, right now I just have to put this site up with no validation. Thanks-----Original Message----- From: Beauford Sent: January 15, 2007 10:26 PM To: 'PHP' Subject: RE: [PHP] I lied, another question / problem Does anyone have any idea to this problem? All the code is in the emails I have written to the list. I have temporarily solved the problem by writing my own function not using any pregs, eregs, or any other regs and it works perfectly. It's probably not considered good programming, but it works the way it is supposed to. I would however like to know what the issue is with the original code, or if this is actually a bug in PHP. Thanks--PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php-----Original Message----- From: Beauford [mailto:phpuser@netscan.ca] Sent: January 15, 2007 7:22 PM To: 'PHP' Subject: RE: [PHP] I lied, another question / problemwhat I am-----Original Message----- From: 'Roman Neuhauser' [mailto:neuhauser@sigpipe.cz] Sent: January 15, 2007 7:53 PM To: Beauford Cc: 'PHP' Subject: Re: [PHP] I lied, another question / problem # phpuser@netscan.ca / 2007-01-15 18:33:31 -0500:pages withocurrencesFrom: Roman Neuhauser [mailto:neuhauser@sigpipe.cz] # phpuser@netscan.ca / 2007-01-15 16:31:32 -0500:I have file which I use for validating which includes the following function: function invalidchar($strvalue) { if(!ereg("^[[:alpha:][:space:]\'-.]*$", $strvalue)) {That regexp matches if $strvalue consists of zero or morewhose numericof a letter, a whitespace character, and any characteryour locale.value lies between the numeric values of "'" and "." inZero or more means it also matches an empty string.I'm still confused. This works perfectly on my other twothe singlethe exact same code. So why is it only this one page thatis causing a problem? I don't know, I don't care. You have enough problems withregex, let's concentrate on fixing this first.This certainly has a bearing. If the code works here then there is nothing wrong with the code. There is something else going on.The problem is that it is returning *something*, and that'sIf I enter the word "test" in my form, without the quotes,then why isthe fuction returning anything since this is a valid entry.Should itnot only return a value if there is a problem.I don't understand that paragraph. The regexp matches, and the function returns *nothing* just as you programmed it. That, of course, means that the variable you are assigning this *nothing* gets set to *nothing*, which, in PHP lingo, is null.trying to figure out. If I put this in my code after I do the checking it works, but it should not work if the function is retuning *nothing*. So the original question remains, what is being returned and why? If($formerror) echo "Testing"; This will display Testing -it shouldnot display anything since nothing should be returned.which logicallyyou tryingAll I want to accomplish here is to allow the user to entera to z, Ato Z, and /\'-_. and a space. Is there a better way to do this?1. Do you really want to let them enter backslashes, or areto "escape" the apostrophe? 2. Does that mean that "/\'-_." (without the quotes) and "" (that'sthree spaces) are valid entries?Where do you see 3 spaces? In any event, I don't think this is the problem. As I have said the code works fine on two other pages,suggests that there is something on this page that is causing a problem. Thanks -- PHP General Mailing List (http://www.php.net/) Tounsubscribe, visit:http://www.php.net/unsub.php