RE: [PHP] Regular Expression

From: Date: Tue, 01 Jul 2003 14:10:04 +0000
Subject: RE: [PHP] Regular Expression
Groups: php.general 
Request: Send a blank email to php-general+get-153557@lists.php.net to get a copy of this message
[snip] That would have been my first choice also, however, with the # and - being legal, things like ctype_alnum and others don't work out. [/snip] Here is an example of something that I did before; $alphachar = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; $ld1alpha = strspn($ld1, $alphachar); if(strlen($ld1) != $ld1alpha){ $err[$i] = "The LD1 may only contain alpha characters.<br>\n"; $i++; } int strspn ( string str1, string str2) - Returns the length of the initial segment of str1 which consists entirely of characters in str2. You could add - and # to $alphachar Now, in this case $ld1aplpha would be the same length as the string length of the input field where the characters are contained in $alphachar. This is used as one of the steps in a verification/validation procedure on a large internal form. Just another solution to the problem HTH!

« previous php.general (#153557) next »