Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. The minimum length required for the password
  2. The type of regular expression to use, which must be one of the following:
    1. any - Validates anything that meets the minimum length requirement
    2. any_no_space - Validates anything that meets the minimum length requirement and does not contain spaces
    3. alpha_num - Validates anything that meets the minimum length requirement and is alpha-numeric
    4. alpha - Validates anything that meets the minimum length requirement and contains only alpha characters
    5. num - Validates anything that meets the minimum length requirement and contains only integers
    6. custom - Specifies that you want to set your own custom regular expression as the next parameter
  3. The custom regular expression you would like to use, if the type of regular expression is set to "custom"

Code Block
languagephp
<?php
	...
	$rules = array(
		'password1' => array(
			'format' => array(
				'rule' => array("isPassword", 8, "alpha_num"),
				'message' => "Password1 must be at least 8 characters in length, and alpha-numeric."
			)
		),
		'password2' => array(
			'format' => array(
				'rule' => array("isPassword", 0, "custom", "/^([a-z][0-9]+){12,}$/Di"),
				'message' => "Password2 must begin with a letter, followed by only numbers, no less than 12 characters in length."
			)
		)
	);
	...
?>

 

isDate

This built-in rule determines whether the given string is in a valid date format. It may also accept minimum and maximum date values as parameters to be used in determining whether the date to be validated is within the given range. The dates may be string-formatted dates, or UNIX timestamps.

The rule accepts multiple parameters:

  1. The minimum date
  2. The maximum date

Code Block
languagephp
<?php
	...
	$rules = array(
		'date_begins' => array(
			'format' => array(
				'rule' => "isDate",
				'message' => "The date_begins is not in a valid date format."
			)
		),
		'date_ends' => array(
			'format' => array(
				'rule' => array("isDate", "2013-05-01", "2013-06-01"),
				'message' => "The date_ends must be a valid date between May 1, 2013 and June 1, 2013."
			)
		)
	);
	...
?>

 

matches

This built-in rule determines whether a given string matches a custom regular expression.

This rule accepts multiple parameters

  1. The regular expression

Code Block
languagephp
<?php
	...
	$rules = array(
		'phone_number' => array(
			'format' => array(
				'rule' => array("matches", "/^([0-9]{3}\.){2}[0-9]{4}$/"),
				'message' => "The phone number must be of the format ###.###.####"
			)
		)
	);
	...
?>

 

compares

This built-in rule satisfies a logical comparison between the input and your custom comparator.

This rule accepts multiple parameters:

  1. The logical comparison operator, one of:
    1. >
    2. <
    3. >=
    4. <=
    5. ==
    6. ===
    7. !=
    8. !==
  2. The value to compare with

Code Block
languagephp
<?php
	...
	$rules = array(
		'status' => array(
			'format' => array(
				'rule' => array("compares", "==", "active"),
				'message' => "The status must be 'active'."
			)
		)
	);
	...
?>

 

between

This built-in method determines whether the input value is between a minimum and maximum value.

This rule accepts multiple parameters:

  1. The minimum value to compare the value against
  2. The maximum value to compare the value against
  3. A boolean value of false if the rule must validate strictly within the min/max range, or true if the range may include the min and max values themselves

Code Block
languagephp
<?php
	...
	$rules = array(
		'score' => array(
			'format' => array(
				'rule' => array("between", "1", "100", false),
				'message' => "The score must be a number between 2 and 99."
			)
		)
	);
	...
?>

 

minLength

This built-in method determines whether the given value is at least a given character length.

This rule accepts multiple parameters:

  1. The minimum length to require

 

Code Block
languagephp
<?php
	...
	$rules = array(
		'last_name' => array(
			'format' => array(
				'rule' => array("minLength", "3"),
				'message' => "Your last name must be at least 3 characters in length."
			)
		)
	);
	...
?>

 

maxLength

This built-in method determines whether the given value is at most a given character length.

This rule accepts multiple parameters:

  1. The maximum length to require

 

Code Block
languagephp
<?php
	...
	$rules = array(
		'last_name' => array(
			'format' => array(
				'rule' => array("maxLength", "32"),
				'message' => "Your last name must not exceed 32 characters in length."
			)
		)
	);
	...
?>

 

betweenLength

This built-in method determines whether the given value is between both the minimum and maximum character lengths.

This rule accepts multiple parameters:

  1. The minimum length to require
  2. The maximum length to require

 

Code Block
languagephp
<?php
	...
	$rules = array(
		'last_name' => array(
			'format' => array(
				'rule' => array("betweenLength", "3", "32"),
				'message' => "Your last name must be between 3 and 32 characters in length."
			)
		)
	);
	...
?>

 

PHP Rules

In additional to the built-in Input rules, you can also invoke any PHP function as a rule as well.

...