Username.php
00001 <?php
00017 class Dsao_Validate_Username extends Zend_Validate_Abstract
00018 {
00025 public function isValid($username)
00026 {
00027 $this->_setValue($username);
00028
00029
00030 $usernameWithoutUnderscore = str_replace('_', '', $username);
00031
00032
00033 if ( strlen($username) < 4
00034 || strlen($username) > 20)
00035 {
00036 return false;
00037 }
00038
00039
00040 if (is_numeric($usernameWithoutUnderscore))
00041 {
00042 return false;
00043 }
00044
00045
00046 if (substr($username, 0, 1) == '_'
00047 || substr($username, 0, -1) == '_')
00048 {
00049 return false;
00050 }
00051
00052
00053 $validator = new Zend_Validate_Alnum();
00054
00055
00056 if (!$validator->isValid($usernameWithoutUnderscore))
00057 {
00058 return false;
00059 }
00060
00061 return true;
00062 }
00063 }