Welcome Guest, Not a member yet? Register   Sign In
Multiple callbacks and regular expressions in callback
#1

[eluser]JamieBarton[/eluser]
Hi guys,

I haven't done PHP let alone Code Igniter for a good 3 months now and diving back into it with a small application I'm making for my friends university folks. They're wanting to be able to register, post comments about their group project and post to-dos etc..

Now you've got the idea of the project, you'll understand my regular expression needs.

I want to be able to get users to register, by adding in their university e-mail address. I need to set some rules so it will only accept emails which have @University.ac.uk. It is important about the .ac.uk as that is the most common e-mail ending for universities in the UK. So nobody else outside can join. We might expand the project more in future so I don't want to narrow it down to just one university @ email etc..

Next thing is checking if that user exists by looking into the database for that email.

I know I want to be running a callback for the email exists, such as;

Code:
function user_exists($user) {
    $query = $this->db->get_where('users', array('username' => $user));
    
    if($query->num_rows() > 0) {
    
        $this->form_validation->set_message('user_exists', 'The email exists, try another one.');
        
        return FALSE;
    
    } $query->free_result(); return TRUE;
    
}

Obviously, it's going to have to check the regular expression first, then lookup the database if the user is registering as theres no point in looking in the database if the expression is wrong and there is no .ac.uk in there. Maybe I just answered my own question of in what order things need to come, but what / where would I put the regular expression, and what would it be, and how do I define the correct messages, "Not a valid university email address".


All the best, thanks for any help in advance.


Jamie


Messages In This Thread
Multiple callbacks and regular expressions in callback - by El Forum - 09-04-2010, 02:35 PM
Multiple callbacks and regular expressions in callback - by El Forum - 09-05-2010, 04:52 PM



Theme © iAndrew 2016 - Forum software by © MyBB