Jump to content

Search the Community

Showing results for tags 'postal code canada'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. How to validate Canadian Postal Code. I am stumped here and would appreciate any help. I have tried two solutions that I found online any neither one works for me. I must be missing something. 1. " /* Canada Postal code validation */ if($name == 'postal') { $postal = $_POST['postal']; if($postal != '') { if(!preg_match('/^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$/', $postal)) { $result['valid'] = false; $result['reason'][$name] = 'Entered Postal Code is Invalid'; } } } " 2. " /*Canadian Postal code */ function isPostalCode($postal) { $regex = "/^([a-ceghj-npr-tv-z]){1}[0-9]{1}[a-ceghj-npr-tv-z]{1}[0-9]{1}[a-ceghj-npr-tv-z]{1}[0-9]{1}$/i"; //remove spaces $postal = str_replace(' ', '', $postal); if ( preg_match( $regex , $postal ) ) { return $postal; } else { return false; } } " Here is my php file without validation included. " <?php /* Set e-mail recipient */ $myemail = "mufc@shaw.ca"; /* Check all form inputs using check_input function Put these in the order that they appear on the form*/ $firstname = check_input($_POST['firstname'], "Enter your first name"); $lastname = check_input($_POST['lastname'], "Enter your last name"); $ammount = check_input($_POST['ammount'], "Write ammount requested"); $first = check_input($_POST['first'], "Write first mortgage balance"); $estimated = check_input($_POST['estimated'], "Write estimated house value"); $assessed = check_input($_POST['assessed'], "Write assessed house value"); $present = check_input($_POST['present'], "Write Present Address"); $city = check_input($_POST['city'], "Write City/Town"); $email = check_input($_POST['email'],"Write Email Address"); $postal = check_input($_POST['postal'], "Write Postal Code"); $likeit = check_input($_POST['likeit']); $status = check_input($_POST['status'], "Please Choose Marital Status"); $comments = check_input($_POST['comments'], "Write your comments"); /* Canada Postal code validation */ if($name == 'postal') { $postal = $_POST['postal']; if($postal != '') { if(!preg_match('/^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$/', $postal)) { $result['valid'] = false; $result['reason'][$name] = 'Entered Postal Code is Invalid'; } } } /* Let's prepare the message for the e-mail */ $message = "Hello! Your contact form has been submitted by: First Name: $firstname Last Name $lastname E-mail: $email Ammount Requested: $ammount First Mortgage Balance: $first Estimated House Value: $estimated Assessed Value: $assessed Present Address: $present City/Town: $city Postal Code: $postal Marital Status: $status Like the website? $likeit Comments: $comments End of message "; /* Send the message using mail() function */ mail($myemail, $subject, $message); /* Redirect visitor to the thank you page */ header('Location: thanks.htm'); exit(); /* Functions we used */ function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?> <html> <body> <b>Please correct the following error:</b><br /> <?php echo $myError; ?> </body> </html> <?php exit(); } ?> " Thanks in advance.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.