06.15 php saved
jesirose
Tags add more
 
Note
The problem is with my regex. When I enter the following usernames, I get the correct error that they can only contain letters, numbers and _
testing$
te$ting$

The following usernames SHOULD produce the error but DO NOT. What is wrong?
te$ting
$te$ting

($ can be any character that is not num or letter, #, &, etc.)

It appears the problem is when the string ends with a character it shouldn't. What is wrong?
  1. <?php
  2. Class User extends AppModel{
  3.     var $name = 'User';
  4.     var $primaryKey = 'UserID';
  5.  
  6.     var $validate = array(
  7.         'username' => array(
  8.             'inUse'=>array(
  9.                 'rule'=>array('fieldInUse','username', 0),
  10.                 'message'=>'That username is already in use'
  11.             ),
  12.             'alphanumeric' => array(
  13.                 'rule' => array('custom', '/[a-z0-9\_]$/i'),
  14.                 'message' => 'Your username may only use letters, numbers and the underscore character',
  15.             ),
  16.             'between' => array(
  17.                 'rule' => array('between', 4,20),
  18.                 'message' => 'Your username must be between 4 and 20 characters long'
  19.             )
  20.         )
  21.  
  22.  
  23.     //Check if a unique field already has that value
  24.     function fieldInUse($data, $field, $limit){
  25.         $count = $this->find('count', array('conditions'=>array($field => $data[$field])));
  26.         return $count <= $limit;
  27.     }
  28. );
Parsed in 0.068 seconds, using GeSHi 1.0.7.14

Modify this Paste