check email if valid/duplicate from database using codeigniter
<p>i have a code from tutorial that doesn't work well. I don't know why, i am a beginner in codeigniter. I want to submit the button update, if duplicate a text will response below the textbox that the email is exist and also check it if the email is a valid email syntax. </p>

<p>Here is my html code :</p>

<pre><code>&lt;form id="reg_form" class="form-horizontal"&gt;
    &lt;div class="form-group"&gt;
    &lt;label class="control-label col-sm-3" for="curEmail"&gt;New Email&lt;/label&gt;
    &lt;div class="col-sm-6"&gt;
    &lt;input type="text" class="form-control" name="email" id="email" placeholder="youremail@yourcompany.com" required data-fv-emailaddress-message="The value is not a valid email address"&gt;                                                           
    &lt;/div&gt;
    &lt;div class="col-sm-8 ajax_response_result"&gt;&lt;/div&gt;                                                       
    &lt;/div&gt;
    &lt;button onclick="editEmail()" class="btn btn-success btn-sm "&gt;&lt;i class="fa fa-refresh"&gt;&lt;/i&gt; Update Profile&lt;/button&gt;
&lt;/form&gt;
</code></pre>

<p>Here is my ajax:</p>

<pre><code>function editEmail() {

    jQuery.ajax({
    type: "POST",
    url: "&lt;?php echo site_url('manager/profile/check_email') ?&gt;",    
    data: $("#reg_form").serialize(),
    success: function(res) {
     $(".ajax_response_result").html(res);

     }
    });

}
</code></pre>

<p>My CodeIgniter Controller: </p>

<pre><code>public function check_email() {
         $this-&gt;form_validation-&gt;set_rules('email', 'Email', 'required|is_unique[user.user_email]|valid_email');

         $this-&gt;form_validation-&gt;set_message('is_unique', 'The %s is already taken');
         if ($this-&gt;form_validation-&gt;run() == FALSE):
                echo 'Enter valid email.';          
        else :           
            unset($_POST);
            echo 'Available';
        endif;

  }
</code></pre>