Yii 1.1: serial-generator-validator

Generates strings based on template
6 followers

This validator (based on Yii’s “default” (CDefaultValueValidator) validator) aims to generate a string of characters, numbers or the combination of both. The template of the generated strings can be easily changed using the template property.

Requirements

  • tested with Yii 1.1.12 but should work with Yii 1.1.*

Usage

The validator is very straight-forward as has almost the same behavior of the default validator, you only need to provide ( in case you want to change de default template ) the template param.

public function rules(){
     return array(
     array(code’, ‘ext.validators.FSerialGeneratorValidator’,  ‘setOnEmpty’=>true,  ‘template’=>’alfanum(5)-alfa(3)-num(3))
     );
}

The Structure of the template is as follows. There are 3 available placeholders : - alfa(n) –> string of only characters ( A-Z ) - num(n) –> string of only numbers (0-1) - alfanum(n) –> string of combination of characters and numbers.

The param n is the length of the string to be generated using the placeholder. So the template used in the example above “alfanum(5)-alfa(3)-num(3)” will generate strings like: H43JP-DAUK-234. As you can see any other character used besides placeholders will be remain in the generated string.

Total 3 comments

#9935 report it
idenisko at 2012/09/23 06:38pm
ah, sorry

I read so fast and didnt see about template. I think demo decide any misunderstanding

#9933 report it
onemoverx at 2012/09/23 04:26pm
RE: RegExp

What did you mean easier than RegExp? the purpose is not check the structure of the attribute but to generate a string with that template.

#9931 report it
idenisko at 2012/09/23 04:00pm
RegExp

Is it easier than RegExp?

Leave a comment

Please to leave your comment.

Create extension