Uploader

An all around general purpose file uploader for CakePHP. Packaged as a stand alone plugin with file validation, file scanning and support for a wide range of basic mime types.

Begins With

Checks to see if the first character is either a number or letter when validating in the Model.

Function: beginsWith()
Category: CakePHP
Views: 1,247
Permalink - Tinylink

/**
 * Checks to see if the first character is either a number or letter when validating in the Model
 * @param array $data
 * @param string $type
 * @return boolean
 */
function beginsWith($data, $type) {
	$data = array_values($data);
	$first = substr($data[0], 0, 1);
 
	if ($type == 'number') {
		return (is_numeric($first)) ? true : false;
	} else {
		return (!is_numeric($first)) ? true : false;
	}
}

Example Usage

var $validate = array(
	'password' => array(
		'rule' => array('beginsWith', 'letter'),
		'message' => 'Your passwords must begin with a letter'
	)
);

Return to Snippets