<?php

/**
 * Login name validator
 * 
 * Validates user input, ensuring it only contains characters
 * acceptable for a login name.
 *
 * @version DR1.6
 */
class LoginNameValidator extends LengthValidator {



	/**
	 * Constructs a LoginNameValidator instance
	 * 
	 * @param value : the user input to be validated
	 * @param view : the View where any error shall be posted
	 * @param minLength : the minimum acceptable length
	 * @param maxLength : the maximum acceptable length
	 */
	public function __construct($value, IReadableView $view, $minLength = 6, $maxLength = 20) {
		parent::__construct($value, $view, $minLength, $maxLength);
	}



	/**
	 * Validates user input, ensuring it only contains characters
	 * acceptable for a login name.
 	 * 
 	 * @return true if the user input is a valid login name
	 */
	public function valid() {
		// Always check parent validity first
		if (!parent::valid()) {
			return false;
		}
		if (!ereg("^[A-Za-z0-9][A-Za-z0-9_\.]+$", $this->value)) {
			$this->view->errorMessage(__('This field contains invalid characters<br />'
				.'- Allowed characters are letters, digits, "_" and "."<br />'
				.'- It must start with a letter'));
			return false;
		}
		// Login name valid!
		return true;
	}



} // LoginNameValidator

?>