can somebody send me a code that can validate a string of alpha characters and allow space between one string and another. e.g barrack obama. am using codeIgniter and am new to it and all web applications.

Example:

$string = 'barrack obama';
$a = str_replace(' ','',$string);
if($ctype_alpha($a))
{
   echo $string;
}
else
{
   echo 'error';
}

If data is coming from a form I suggest you to look at the User Guide, you can set up a callback:

# validation rule
$this->form_validation->set_rules('name', 'Name', 'callback_check_string');

# callback
function check_string($str)
{
    return ctype_alpha(str_replace(' ','',$str)) ? true : false;
}

More info: http://codeigniter.com/user_guide/libraries/form_validation.html#callbacks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.