Welcome Guest, Not a member yet? Register   Sign In
[Solved] form_validation how to prevent space in username
#1

[eluser]Ahmed Iqbal[/eluser]
hello,

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....!
#2

[eluser]John_Betong_002[/eluser]
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
 
 
#3

[eluser]Ahmed Iqbal[/eluser]
thanks

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

[eluser]cideveloper[/eluser]
Use a callback
Code:
$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;
    }
    else
    {
        return TRUE;
    }
}
#5

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

[eluser]CroNiX[/eluser]
[quote author="Ahmed Iqbal" date="1307048083"]

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

[/quote]
I just thought that was a funny comment coming from someone with a space in their username ;-P
#7

[eluser]osci[/eluser]
lol CroNiX
you sure have eagles' eyes Smile
#8

[eluser]regal2157[/eluser]
lol CroNiX as well. that's just hilarious. I didn't see that one!
#9

[eluser]John_Betong_002[/eluser]
 
[b]@CroNiX[b] - very funny, a good start for today Smile Smile Smile
 
 
#10

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




Theme © iAndrew 2016 - Forum software by © MyBB