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.
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
I read so fast and didnt see about template. I think demo decide any misunderstanding
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.
Is it easier than RegExp?
Leave a comment
Please login to leave your comment.