I would like to create a validate function for numbers only, actually I have those ones that works fine, and I tried to create one myself, but it's unfortunately not working. Here are the alphanumeric and others working fine :
// Validators
private function custom($validator, $value)
{
return call_user_func($validator, $value, $this->request, $this->id);
}
private function alphanumeric($value, $custom)
{
return preg_match('/^(['.$custom.'a-z0-9_]*)$/i', $value);
}
private function valid_email($value)
{
return preg_match('/^\S+@\S+\.\S+$/', $value);
}
And the one I tried to create by modifying the alphanumeric one :
private function numbers_only($value, $custom)
{
return preg_match('/^(['.$custom.'0-9_]*)$/i', $value);
}
What's wrong with this one ?
EDIT : I also have a JS helping with the form, for alphanumeric it's :
Form.prototype.alphanumeric = function(value, custom)
{
return !value.replace(new RegExp('['+custom+'a-z0-9_]', 'ig'), '').length;
};
What would be the JS for numeric only ?