regex - PHP are patterns still necessary or does filter_var take care of it all -


as reading article morning came across this

most people tend think of data validation immensely tedious process 1 either:

compares data want validate against every possible combination can think of. tries find golden regular expression match every possible combination.
a combination of two.
there obvious problems above listed:

it's absolutely time consuming. there high chance of error. fortunately, beginning version 5.2, php has included great function called filter_var takes away pain of data validation.

are patterns still neccessary or filter_var all.

if patterns mean regular expressions, answer question yes. why? built in filters may not sanitize or validate data how want. filters may overly broad, or may conform rigidly standards particular circumstance. filters many not conform standards @ all.

for example, filter_sanitize_email , filter_validate_email might might allow strange email addresses that, while technically legal in rfc sense, may undesirable depending on needs. developer, creator of application, decide want accept e-mail address.

the php filter creators understood 1 size fits impractical proposition. therefore, can supply own sanitizing/validating filter filter_callback , own validating filter using filter_validate_regexp. @ square one? better off?

the real question willing buy in , accept "filtering framework/methodology" established php filter system. i? use filter system first pass, use own crafted sanitizers , validators (yes, use both filter_callback , filter_validate_regexp on top of generic sanitizers/validators). true me when processing html forms, no longer use $_post , $_get. use filter_input_array() .

so, mr. smithyyy, don't reinvent wheel, think yourself. key using php filter system create system, , (like me) means wrapping filter functions in class. using various class properties might store predefined filters, 1 imagine system various methods, using loops, filter data, leaving final output of array, or bad 1 (which can take action on, based on particular circumstance). but, mr. wall of perl community notes, "there's more 1 way it."


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -