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 [message #182665 is a reply to message #182663] Sun, 25 August 2013 18:38 Go to previous messageGo to previous message
J.O. Aho is currently offline  J.O. Aho
Messages: 194
Registered: September 2010
Karma:
Senior Member
On 25/08/13 19:51, Twayne wrote:
> Hi all,
>
> I'm still working on the postal code issue, for Canada at the moment and
> I'm still stuck.
>
> I've decided to try:
> = See if it's alpha-numeric
> = Create an array
> = See if there is a space where it belongs
> = Validate for digits in proper positions
> = Since it's alpha-numeric, the 3 characters left must be Alphabetic.
> If the validations work, keep going.
> If not, halt & allow for a re-entry.
>
> The ctype statement will NOT work in any form and throws various errors
> regardless of wher I place it or what I use s the var. Remove the entire
> ctype, and everything works again.
>
> In code, this equates to, as best as I can:
> --------------------------------------------------------------------------- ------------------------
>
> IF(strlen($zip) === 7) {
> echo "Zip appears to be Canadian . <br />";
> }
> // ================== NOW LOOK TO SEE IF IT'S ALPHA-NUMERIC
>
> * if (ctype_alnum(str_split($zip,1)) { <---- Throws error [1]
> * echo "Is Alpha Numeric.";
> *}

I assume you have just added the '*' first in the line to show which
rows you are talking about.

Simple maths will show your error, lets count your opening parentheses

if (ctype_alnum(str_split($zip,1)) {
1 2 3

and now the number of closing parentheses

if (ctype_alnum(str_split($zip,1)) {
12

So we get 3 opening parenthesis and 2 closing, this is what the "Parse
error: syntax error, unexpected '{'" is about, you need to close all
your parentheses.


You know you will end up with loads of if cases if you keep on doing
this instead of using a regular expression, this would speed it up and
make your code a lot easier to read (case insensitive):


if(preg_match("/^[a-z]\d[a-z] \d[a-z]\d$/i",$postcode)) {
// this could be a valid Canadian postcode
// just add what you need to do to check it against
// Canadian Post, worst case use the "Find a post office"
}


--

//Aho
[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: Sat Nov 30 12:01:44 GMT 2024

Total time taken to generate the page: 0.04287 seconds