PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 12th, 2012, 03:27 PM
Jyncka's Avatar
Jyncka Jyncka is offline
We're trapped inside a game!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Location: Maryland
Posts: 297 Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)  Folding Points: 37258 Folding Title: Starter FolderFolding Points: 37258 Folding Title: Starter Folder
Time spent in forums: 5 Days 8 h 35 m 57 sec
Reputation Power: 902
Why does the order matter?

I'm not good with regex, much more than email validation loses me. But I'm working on an older code repo that has some filtering going on for its form validation functions.

This is how the function validates a person's first or last name:

PHP Code:
 filter_var('3 32pm'FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/[a-zA-Z][a-zA-Z0-9-_\.]{2,32}/"))); 


And in testing our form out, my coworker put in "3 32 pm" in the last name field. The validation failed so I took the above snippet and tested it with the following values with the respective values returned by var_dump():

3 32 pm - false
pm3 32 - pm3 32
3 pm32 - 3 pm32
3pm pm32 - 3pm pm32
3 pm 32 - false

I rearranged the regex like so, with the number range first:

PHP Code:
 filter_var('3 pm 32'FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/[0-9a-zA-Z][a-zA-Z-_\.]{2,32}/"))); 


And tested the above values that produced a false result before; this time they returned the filtered string, rather than false.

What I don't understand is why the order mattered here, shouldn't the PHP function evaluate the entire string before returning a value? If my input contained '$' or '@' I'd expect it to be removed, but this thing with the numbers seems odd. I can't think of why someone would put the time in for their name and I can fix this bug, but the issue is still really weird.
__________________
"Those who can make you believe absurdities can make you commit atrocities."

Reply With Quote
  #2  
Old November 12th, 2012, 04:36 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,679 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 1 h 46 m 33 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
It's not order. You changed the regex. You changed the definition of what's valid and what isn't. Before it was failing names because they started with a number. Now that you've told it that a leading number is okay it will not fail them.

Reply With Quote
  #3  
Old November 12th, 2012, 04:51 PM
Jyncka's Avatar
Jyncka Jyncka is offline
We're trapped inside a game!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Location: Maryland
Posts: 297 Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)  Folding Points: 37258 Folding Title: Starter FolderFolding Points: 37258 Folding Title: Starter Folder
Time spent in forums: 5 Days 8 h 35 m 57 sec
Reputation Power: 902
That actually answers the other question I couldn't figure out. I had (inaccurately, I realize now) thought that a regex expression could be ordered in any way and it would work the same way. But when I think of symbols such as "*", "^" and "?" I realize that's incorrect.

Thanks, Requinix, some more fundamentals just clicked for me.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Why does the order matter?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap