serial-generator-validator Generates strings based on template

  1. Requirements
  2. Usage

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.

1 0
6 followers
342 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Validation
Developed by: onemoverx
Created on: Sep 23, 2012
Last updated: 12 years ago

Downloads

show all

Related Extensions