PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
elitecodex
Forum Newbie
Posts: 5 Joined: Thu Mar 11, 2004 2:01 pm
Location: FL
Post
by elitecodex » Thu Mar 11, 2004 2:01 pm
Hello all!!
The input is "1234 5678" and has to allow for any symbol where the whitespace is (like a dash or something). Looks good to me, so if anyone could lend a hand, it would be great... thanks!!
Code: Select all
<?php
if ( strlen($_POSTї'jobnumber'] == 9) && preg_match("/^(\d{4}ї\-\s]\d{4})$/", $_POSTї'jobnumber']) )
{
echo "It worked!!";
}
?>
I have used this function many times and have always been able to figure it out... Im at a lost as to why this isnt working... makes sense to me. I also tried
"/([0-9]{4})?([0-9]{4})/" and it didnt work either. Any information would be greatly appreciated... thanks!
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Thu Mar 11, 2004 2:10 pm
What exactly doesn't work? String "1234 5678" doesn't match your regexp?
TheBentinel.com
Forum Contributor
Posts: 282 Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio
Post
by TheBentinel.com » Thu Mar 11, 2004 2:18 pm
elitecodex wrote: Hello all!!
The input is "1234 5678" and has to allow for any symbol where the whitespace is (like a dash or something). Looks good to me
Looks good to me, too. I downloaded this tool and checked your regexp:
http://weitz.de/files/regex-coach.exe
It worked in that tool. It accepted "1234 5678" and "1234-5678", but not "1234_5678" or "123405678".
Are you sure your code is executing at all? Until you're comfortable with the regexp, I'd try the code as:
Code: Select all
print (preg_match("/^(\d{4}[\-\s]\d{4})$/", "1234 5678"))
It ought to output 0 if it doesn't match, 1 if it does.
elitecodex
Forum Newbie
Posts: 5 Joined: Thu Mar 11, 2004 2:01 pm
Location: FL
Post
by elitecodex » Thu Mar 11, 2004 2:19 pm
Right.
The strlen() part works just fine (I have dumped that out and seen it... returns true). The preg_match() returns false. Thats my problem.
patrikG
DevNet Master
Posts: 4235 Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK
Post
by patrikG » Thu Mar 11, 2004 2:21 pm
Try
Code: Select all
$test="1234/5678";
if(preg_match("/^(\d{4}[\W]\d{4})$/", $test))
{
echo "It worked!!";
}
else
echo "nope";
PHP Manual wrote:
\W - any "non-word" character
Last edited by
patrikG on Thu Mar 11, 2004 2:24 pm, edited 1 time in total.
elitecodex
Forum Newbie
Posts: 5 Joined: Thu Mar 11, 2004 2:01 pm
Location: FL
Post
by elitecodex » Thu Mar 11, 2004 2:21 pm
well, right before that line I do a var_dump of $_POST('jobnumber') and that gets executed, so I can see whats in it.
Ill have to download that tool when I get home... if it matches, why would it return not execute whats inside the if statement? This is strange...
I can paste the entire function if you like... But Im certain its being executed.
elitecodex
Forum Newbie
Posts: 5 Joined: Thu Mar 11, 2004 2:01 pm
Location: FL
Post
by elitecodex » Thu Mar 11, 2004 2:24 pm
patrikG - it worked
patrikG
DevNet Master
Posts: 4235 Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK
Post
by patrikG » Thu Mar 11, 2004 2:24 pm
elitecodex
Forum Newbie
Posts: 5 Joined: Thu Mar 11, 2004 2:01 pm
Location: FL
Post
by elitecodex » Thu Mar 11, 2004 2:26 pm
SON OF A #%$@&!
It was the stupid strlen() part... I dont understand... a var_dump($_POST['jobnumber']); says that its a string (9)... anyhow, I can figure that part out... I got the hard part out of the way
Thanks for all the help guys!!
Will