Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #10616 > unrolled thread
| Started by | Twayne <nobody@spamcop.net> |
|---|---|
| First post | 2013-08-25 13:51 -0400 |
| Last post | 2013-08-27 17:18 -0400 |
| Articles | 6 on this page of 26 — 10 participants |
Back to article view | Back to comp.lang.php
CTYPE Twayne <nobody@spamcop.net> - 2013-08-25 13:51 -0400
Re: CTYPE Richard Yates <richard@yatesguitar.com> - 2013-08-25 11:21 -0700
Re: CTYPE Twayne <nobody@spamcop.net> - 2013-08-25 15:00 -0400
Re: CTYPE Richard Yates <richard@yatesguitar.com> - 2013-08-25 12:05 -0700
Re: CTYPE "J.O. Aho" <user@example.net> - 2013-08-25 20:38 +0200
Re: CTYPE Twayne <nobody@spamcop.net> - 2013-08-25 15:28 -0400
Re: CTYPE Richard Yates <richard@yatesguitar.com> - 2013-08-25 13:16 -0700
Re: CTYPE Twayne <nobody@spamcop.net> - 2013-08-26 11:49 -0400
Re: CTYPE Christoph Michael Becker <cmbecker69@arcor.de> - 2013-08-25 22:19 +0200
Re: CTYPE Twayne <nobody@spamcop.net> - 2013-08-26 12:15 -0400
Re: CTYPE Fiver <numeralfive@gmail.com> - 2013-08-25 22:42 +0200
Re: CTYPE Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-08-26 10:25 +0200
Re: CTYPE The Natural Philosopher <tnp@invalid.invalid> - 2013-08-26 09:29 +0100
Re: CTYPE Twayne <nobody@spamcop.net> - 2013-08-26 12:37 -0400
Re: CTYPE Norman Peelman <npeelman@cfl.rr.com> - 2013-08-25 15:11 -0400
Re: CTYPE Tim Streater <timstreater@greenbee.net> - 2013-08-25 23:04 +0100
Re: CTYPE THREAD RESOLVED Twayne <nobody@spamcop.net> - 2013-08-25 15:35 -0400
Re: CTYPE THREAD RESOLVED Fiver <numeralfive@gmail.com> - 2013-08-26 20:07 +0200
Re: CTYPE THREAD RESOLVED The Natural Philosopher <tnp@invalid.invalid> - 2013-08-26 20:19 +0100
Re: CTYPE THREAD RESOLVED Fiver <numeralfive@gmail.com> - 2013-08-26 22:51 +0200
Re: CTYPE THREAD RESOLVED Jerry Stuckle <jstucklex@attglobal.net> - 2013-08-26 16:57 -0400
Re: CTYPE THREAD RESOLVED Twayne <nobody@spamcop.net> - 2013-08-27 17:20 -0400
Re: CTYPE THREAD RESOLVED Jerry Stuckle <jstucklex@attglobal.net> - 2013-08-27 19:47 -0400
Re: CTYPE THREAD RESOLVED Tim Streater <timstreater@greenbee.net> - 2013-08-26 22:07 +0100
Re: CTYPE THREAD RESOLVED Twayne <nobody@spamcop.net> - 2013-08-28 08:49 -0400
Re: CTYPE THREAD RESOLVED Twayne <nobody@spamcop.net> - 2013-08-27 17:18 -0400
Page 2 of 2 — ← Prev page 1 [2]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2013-08-26 16:57 -0400 |
| Subject | Re: CTYPE THREAD RESOLVED |
| Message-ID | <kvgff7$n93$1@dont-email.me> |
| In reply to | #10635 |
On 8/26/2013 4:51 PM, Fiver wrote:
> On 2013-08-26 21:19, The Natural Philosopher wrote:
>> On 26/08/13 19:07, Fiver wrote:
>>> For the Canadian zip codes:
> [snip]
>>> 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";
>>> }
> [snip]
>
>> Now key in SW1A 1AA as a postcode and see what it does with it.
>
> It won't be recognized as a Canadian zip code, which is as it should be.
>
>> there is a world beyond north America.
>
> Meh, that's just a rumor.
> And even if there is, I heard that there be dragons.
>
> The question was about US and Canadian zip codes, so what's your point?
>
>
> regards,
> 5er
>
TNP just hates to be left out (of ANYTHING).
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[toc] | [prev] | [next] | [standalone]
| From | Twayne <nobody@spamcop.net> |
|---|---|
| Date | 2013-08-27 17:20 -0400 |
| Subject | Re: CTYPE THREAD RESOLVED |
| Message-ID | <kvj56v$d08$2@speranza.aioe.org> |
| In reply to | #10636 |
On 2013-08-26 4:57 PM, Jerry Stuckle wrote: > > TNP just hates to be left out (of ANYTHING). > > Trolling again I see.
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2013-08-27 19:47 -0400 |
| Subject | Re: CTYPE THREAD RESOLVED |
| Message-ID | <kvjdqs$m31$1@dont-email.me> |
| In reply to | #10639 |
On 8/27/2013 5:20 PM, Twayne wrote: > On 2013-08-26 4:57 PM, Jerry Stuckle wrote: > >> >> TNP just hates to be left out (of ANYTHING). >> >> > > Trolling again I see. > > ROFLMAO. And you said you plonked me. I knew you couldn't do it! -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | Tim Streater <timstreater@greenbee.net> |
|---|---|
| Date | 2013-08-26 22:07 +0100 |
| Subject | Re: CTYPE THREAD RESOLVED |
| Message-ID | <timstreater-AEA026.22071126082013@news.individual.net> |
| In reply to | #10635 |
In article <kvgf5b$lfm$1@dont-email.me>, Fiver <numeralfive@gmail.com> wrote: > On 2013-08-26 21:19, The Natural Philosopher wrote: > > there is a world beyond north America. > > Meh, that's just a rumor. > And even if there is, I heard that there be dragons. > > The question was about US and Canadian zip codes, so what's your point? I suspect it was that Canadians don't have zip codes. -- Tim "That excessive bail ought not to be required, nor excessive fines imposed, nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
[toc] | [prev] | [next] | [standalone]
| From | Twayne <nobody@spamcop.net> |
|---|---|
| Date | 2013-08-28 08:49 -0400 |
| Subject | Re: CTYPE THREAD RESOLVED |
| Message-ID | <kvkrju$eo4$2@speranza.aioe.org> |
| In reply to | #10634 |
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`
[toc] | [prev] | [next] | [standalone]
| From | Twayne <nobody@spamcop.net> |
|---|---|
| Date | 2013-08-27 17:18 -0400 |
| Subject | Re: CTYPE THREAD RESOLVED |
| Message-ID | <kvj528$d08$1@speranza.aioe.org> |
| In reply to | #10633 |
On 2013-08-26 2:07 PM, 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!
>> -----------------------------------
>> $zip = check_input($zip);
>> $zip = strtoupper($zip);
>> // DETERMINE IF US POSTAL CODE
>> if(strlen($zip)===5) {
>> echo "U.S. postal code used "; }
>> IF (is_numeric($zip)) {
>> echo " and is 5 digits.";
>> }
>> 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.
OOPS! Good catch!
> 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
Good point.
>
> ... && $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).
Agreed; the original array code was removed at that point in the coding.
>
> 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
...
Hmm, ALL great observations; thanks much.
I'll have a look at everything you mentioned here. It's much more
efficient than I've been putting together so far.
Regards,
Twayne`
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.php
csiph-web