Skip to content

Instantly share code, notes, and snippets.

@wlkns
Created October 15, 2013 18:32
Show Gist options
  • Save wlkns/6996382 to your computer and use it in GitHub Desktop.
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/
<?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