Welcome Guest, Not a member yet? Register   Sign In
testing input for email address
#1

[eluser]k7faq[/eluser]
still rather green around the edges with CI but learning as quick as possible. Any assistance is _greatly_ appreciated!

Have a form. Need to test in validation if the userName field has been populated by the visitor as an email address. (testing for other ways not necessary right now, i.e. meatnospamdotcom)
Testing the input to see if valid email address is what is catching me. I am using 'valid_email' for the actual email address field.

I am already performing a callback_, this would be an optimum area to handle this in...

snippets of code:

create_account(){
$this->form_validation>set_rules('userName','Username',
'callback__userName_check|trim|required|min_length[5]');
} // function create_account

function _username_check($userName) {
// verify user name not in use
$this->db->where('userName', $this->input->post('userName'));
$query = $this->db->get('users');

if($query->num_rows > 0){
$this->form_validation->set_message('_userName_check',
'Username already in use. Please select another.');
return FALSE;
} // if num_rows
} // function: _username_check
#2

[eluser]Dennis Rasmussen[/eluser]
Exactly what is the problem?
#3

[eluser]k7faq[/eluser]
need to find way to test user name to see if it is an email address

username shall not be an email address...
#4

[eluser]Twisted1919[/eluser]
Code:
$this->form_validation->set_rules('username','Username','trim|required|min_length[5]|max_length[50]|alpha_dash');
#5

[eluser]Twisted1919[/eluser]
Btw, i don't use calllbacks because i just believe it's a waste of time .
What can you do is to set some basic validation rules, once the form pass the validation, you can easily check the database for duplicates, or just like your case, check to see if the username is an email address, which is very easy to do
Code:
//simple validation passed
$user = $this->input->post('username',TRUE);
if($this->form_validation->valid_email($user))
{
//error , no email allowed ... etc etc etc
}
#6

[eluser]k7faq[/eluser]
Twisted and Dennis,

Thank you for your replies. that took care of it!




Theme © iAndrew 2016 - Forum software by © MyBB