Wixel/GUMP — Issue #5: what about a "name" validator ?
Author: ben-s
Created: 2012-01-17 09:43:22+00:00
State: open

I'm new to github and I didn't find how to pull new requests, so I'm sharing a validator that has been useful to me.

I'm devleopping a new subscription form on my website and want to check if the firstname and lastname are correctly typed in.
For my French website, I need to accept alpha characters, spaces, dashes (but not underscores), apostrophes and accentuated characters

For this, I have created the following method in the gump Class :

/**
* Determine if the provided value contains only alpha_numeric characters with dashes, underscores, and apostrophes
*
* @static
* @access protected
* @param string $field
* @param array $input
* @return mixed
*/
protected static function validate_alpha_dash_space_apo($field, $input, $param = NULL)
{
if(!isset($input[$field]))
{
return;
}

if(!preg_match("/^([-a-zÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïñðòóôõöùúûüýÿ '-])+$/i", $input[$field]) !== FALSE)
{
return array(
'field' => $field,
'value' => $input[$field],
'rule'	=> __FUNCTION__
);
}
}

I hope that will be useful for other people.