nguyendh
(Duynguyen0511)
December 30, 2012, 4:39am
1
Hi guys,
I have a form which shows Zip Code or Postal Code depends on where the user is coming from. I would like to know if Yii has built-in validation for Zip Code or Postal Code.
I am talking about rules declared in rules function in Model. (http://www.yiiframework.com/doc/guide/1.1/en/form.model#declaring-validation-rules )
If there are none built-in zip/postal code, Please guide me on how to create one.
Thank you,
softark
(Softark)
December 30, 2012, 5:28am
2
You can use CRegularExpressionValidator.
http://www.yiiframework.com/doc/api/1.1/CRegularExpressionValidator
See the comments at the bottom for the sample codes.
LastDay
(Egorsmir)
December 30, 2012, 11:22am
3
To complete previous post, here is link to regular expressions for USA / Canada zip code validation - http://geekswithblogs.net/MainaD/archive/2007/12/03/117321.aspx
Cuji12
(Cu Janeway)
November 12, 2022, 7:21pm
4
In-case people are looking at how to use these in the context of rules, here you go:
[[‘yourProperty’], ‘match’, ‘pattern’ => ‘yourRegularExpression’]