I'm making a basic validation class for a CMS I'm developing. The following function verifies that a username contains nothing but letters, numbers and underscores. How can I extend this regexp to make sure that $value is no less than 5 characters and no more than 20?
function isUsername($value, $msg) {
if(eregi("[^a-z0-9_]", $value)) {
$this->errorlist[] = array("value" => $value, "msg" => $msg);
return false;
} else {
return true;
}
}
Also, I have considered using a method like they used in this tutorial at DevShed, in which I could pass a validation function the name of a variable, and have it use this internal class function to retreive the value:
function _getValue($field)
{
global ${$field};
return ${$field};
}
This way I could fetch the value from within my validation class, and in the case of error I can return the name of the variable it err'd on. This works fine for normal variables, but when it comes to passing an associative array (say $dirtydata["username"]) it cannot retreive the variable name. Is there a way to make this function find return the correct variable name, or is this only possible for a regular variable?
Thanks for any help in advance