• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Solved] form_validation how to prevent space in username

[eluser]Ahmed Iqbal[/eluser]

i know codeigniter form validation...!
please, let me know how i prevent blank space in username....!

because some idiot users put space in their username....!

Please suggest me....!

Try this:

1. accept the user's input
2. store using url_title();
3. retrieve and display using str_replace('-', ' ' , $username);
If the user inputs a dash then this will remove the displayed dash.

This requires further logic but at least it's a start Smile

[eluser]Ahmed Iqbal[/eluser]

but i want when user signup and enter username with space validation error appear. hey don't try to enter space in your username :}

Use a callback
$this->form_validation->set_rules('username', 'Username', 'trim|required|valid_email|callback_username_check_blank|xss_clean');

function username_check_blank($str)

    $pattern = '/ /';
    $result = preg_match($pattern, $str);

    if ($result)
        $this->form_validation->set_message('username_check', 'The %s field can not have a " "');
        return FALSE;
        return TRUE;

[eluser]Ahmed Iqbal[/eluser]
Thanks for help...
its work

[quote author="Ahmed Iqbal" date="1307048083"]

because some idiot users put space in their username....!

I just thought that was a funny comment coming from someone with a space in their username ;-P

lol CroNiX
you sure have eagles' eyes Smile

lol CroNiX as well. that's just hilarious. I didn't see that one!

[b]@CroNiX[b] - very funny, a good start for today Smile Smile Smile

[eluser]Ahmed Iqbal[/eluser]
@CroNiX, lolz Big Grin

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.