FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » CTYPE
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: CTYPE THREAD RESOLVED [message #182688 is a reply to message #182681] Wed, 28 August 2013 12:49 Go to previous messageGo to previous message
bill is currently offline  bill
Messages: 310
Registered: October 2010
Karma:
Senior Member
On 2013-08-26 3:19 PM, The Natural Philosopher wrote:
> On 26/08/13 19:07, Fiver wrote:
>> On 2013-08-25 21:35, Twayne wrote:
>>> If anyone is interested, here's the code I ended up with. It still
>>> needs to validate alphabetic & numeric array positions but that should
>>> be reasonably simple to add by checking the array positions for alpha or
>>> digit characters.
>>>
>>> Thanks for all the help!
....

>>> }
>>> IF(strlen($zip) === 7) {
>>> echo "Zip appears to be Canadian . <br />";
>>> }
>>> // ================== NOW LOOK TO SEE IF IT'S ALPHA-NUMERIC
>>>
>>> // ================ LET'S ASSIGN IT TO AN ARRAY
>>> echo ' <pre>';
>>> print_r(str_split($zip,1));
>>> echo '</pre>';
>>>
>>> // ================= check space is where it belongs
>>> if($zip[3] === " ") {
>>> echo "<br />Space in correct place<br />";
>>> }
>>>
>>> $sUser = $zip;
>>> $aValid = array(' ');
>>> if(!ctype_alnum(str_replace($aValid, '', $sUser))) {
>>> echo "Username has a problem";
>>> echo 'Your Postal Code is NOT properly formatted.';
>>> }
>>> else {
>>> echo "Postal code is properly formatted as ALPHA NUMERIC with ONE SPACE
>>> as the 4th character";
>>> }
>> For the US zip codes:
>>
>> is_numeric() is not the correct function to use here. "+.1e1" and
>> "0xCAB" are both numeric strings and would pass as US zip codes.
>> Better solution:
>>
>> if (strlen($zip) == 5 && ctype_digit($zip)) {
>> echo "looks like a US zip code\n";
>> }
>>
>> Better yet: check for known bad zip codes as well
>>
>> ... && $zip != "00000" && $zip != "99999" && I don't know, some more
>>
>> For the Canadian zip codes:
>>
>> Your code has a comment "let's assign it to an array", and you also
>> wrote that you still needed to validate the array positions, but you
>> never do create an array (except for the unnecessary one in $aValid,
>> which should probably be a string).
>>
>> Anyway, you're right that you still need to check the characters to the
>> right and left of the space, or strings like "x " and " 3 "
>> would be seen as valid zip codes. Here's one way to do it:
>>
>> if (strlen($zip) == 7
>> && $zip[3] == " "
>> && ctype_alpha($zip[0] . $zip[2] . $zip[5])
>> && ctype_digit($zip[1] . $zip[4] . $zip[6]))
>> {
>> echo "looks like a Canadian zip code\n";
>> }
>>
>> Note the two closing parens after $zip[6] ;)
>>
>>
>> regards,
>> 5er
>>
>>
>> PS: No regexes were killed or injured in the production of this message.
>>
>
> Now key in SW1A 1AA as a postcode and see what it does with it.
>
> there is a world beyond north America.
>

I hear ya; Things will only get checked if len=7 and that's 8, so ... .
It's finally coming together for me I think.

Thanks,

Twayne`
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: korean character sets
Next Topic: Android app Developers requirements
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 07 00:14:15 GMT 2024

Total time taken to generate the page: 0.04600 seconds