⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Postal Code Validation



eamon250d
  • profile picture
  • Member

Posted 03 January 2016 - 05:16 AM

I wanted to make a function for the validation of postal code to customize an error message if possible. I wonder if you have an idea.

Here's an idea of my function:

// checks postal code format L4X-1S9 

$regex = '/[a-z][0-9][a-z][- ]?[0-9][a-z][0-9]$/i'; 

if( preg_match($regex, $zip) ) 

  echo "Valid postal code";  


Amit Shah
  • profile picture
  • Member

Posted 06 January 2016 - 02:37 AM

Grocerycrud validation is based on codeigniter's base validation rules. In codeigniter - there are ways to add custom validation. Use them, that should give you appropriate solution for the same.

 

Happy GCing :)


mehedicse60
  • profile picture
  • Member

Posted 12 January 2016 - 06:29 AM

Dear Amit Shah,

 

 Can u help me on the following issue?

 

1. I nedd to make a text filed which will not accept any space or special characters like( ^, + , % etc)

 

I USED THE FOLLOWING CODE

$crud->set_rules('pass_no','Passport Number','required|regex_match[/regex/]
but not working ....
 


eamon250d
  • profile picture
  • Member

Posted 13 January 2016 - 17:40 PM

Hello ,
On after me, the solution will be to mix the two code
In the 2nd example, fake it do the same for the postcode and not email.
If someone has a suggestiion I proneur

Thanks

 

http://devtipsforu.blogspot.ca/2009/02/regex-for-validating-canada-postal-code.html

 

http://arjunphp.com/custom-validation-rules-codeigniter/


Amit Shah
  • profile picture
  • Member

Posted 18 January 2016 - 21:00 PM

Well mehedicse60

The solution for you is to use jquery.mask 

 

If you can attach jquery.mask to that field and configur it not accept it - it should work absolutely fantastic

 

Happy GCing :)


eamon250d
  • profile picture
  • Member

Posted 31 January 2016 - 22:58 PM

Hi Amit ,

This is 50% from the solution :

http://jsfiddle.net/XJZvJ/33/

 

I wonder how I can integrate ca in the GC?
Thanks


eamon250d
  • profile picture
  • Member

Posted 01 March 2016 - 10:10 AM

Hi Amit, I try to mix the solution , but no solution to integrat into grocerycrud

 

http://devtipsforu.blogspot.ca/2009/02/regex-for-validating-canada-postal-code.html
https://arjunphp.com/custom-validation-rules-codeigniter/

/****
Add this in your controller:

function zip_check($zip){
$regex = '/[a-z][0-9][a-z][- ]?[0-9][a-z][0-9]$/i';
if( !preg_match($regex, $zip) ) {
  $this->form_validation->set_message('zip_check', 'Zip code is invalid!');
  return false;
}
}

and in your form rule:
$this->form_validation->set_rules('pass_no','Code postal', 'required|callback_zip_check');
****/