Created
October 15, 2013 18:32
-
-
Save wlkns/6996382 to your computer and use it in GitHub Desktop.
CodeIgniter Postcode Validation Form Validation (and global call back functionality), read more at http://wlkns.co/codeigniter/global-form-validation-callback-functionality-and-postcode-checker-in-codeigniter/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php defined('BASEPATH') or die('Direct access to this file is not permitted.') | |
class MY_Form_validation extends CI_Form_validation | |
{ | |
/** | |
* Postcode Validation Callback | |
*/ | |
public function valid_postcode( $string ) | |
{ | |
if ( ! preg_match('/^[A-Z]{1,2}[0-9]{1,2}[A-Z]?[\s]*[0-9]{1}[A-Z]{1,2}$/') ) | |
{ | |
$this->set_message(__FUNCTION__, 'Invalid Postcode entered.'); | |
return FALSE; | |
} | |
return TRUE; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment