NYCPHP Meetup

NYPHP.org

[nycphp-talk] Reg expression to make sure something is not blank

Chris Shiflett shiflett at php.net
Wed Sep 17 12:29:50 EDT 2003


--- David Sklar <sklar at sklar.com> wrote:
> However, you're better off not using a regex for this stuff.
> Instead, do this to make sure a string is between 1 and 35
> characters, after removing leading and trailing whitespace:
> 
> $len = strlen(trim($s));
> if (($len < 1) || ($len > 35)) {
>   // the string is too long or too short
> } else {
>   // the string is just right
> }

+1

This also makes you intent clearer, which will be an important factor in a few
weeks, months, or years. Comments are great, but straightforward code can't be
beat.

Chris

=====
Become a better Web developer with the HTTP Developer's Handbook
http://httphandbook.org/



More information about the talk mailing list