Jump to content

Checking Emial for format


harkly

Recommended Posts

I am testing my userID and my email input from a user. I have it check to make sure that they are not already in the database. I had this working but I tried to modify the email to also check formatting.

 

The formatting is working but it makes my database check not work as well and my out put I want a green box with a check mark. Right now all it gives me is a red box and OK for formatting only. It does not check the database.

 

 

<script language="JavaScript">

function validate(form_id,email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = document.forms[form_id].elements[email].value;
   if(reg.test(address) == false) {
      alert('Invalid Email Address');
      return false;
   }
}
</script>


<SCRIPT type="text/javascript">
<!--
/*
Credits: Bit Repository
Source: http://www.bitrepository.com/web-programming/ajax/userID-checker.html 
*/

pic1 = new Image(16, 16); 
pic1.src = "loader.gif";

$(document).ready(function(){

$("#userID").change(function() { 

var usr = $("#userID").val();

if(usr.length >= 4)
{
$("#status").html('<img src="loader.gif" align="absmiddle"> Checking availability...');

    $.ajax({  
    type: "POST",  
    url: "check.php",  
    data: "userID="+ usr,  
    success: function(msg){  
   
   $("#status").ajaxComplete(function(event, request, settings){ 

if(msg == 'OK')
{ 
        $("#userID").removeClass('object_error'); // if necessary
	$("#userID").addClass("object_ok");
	$(this).html(' <img src="tick.gif" align="absmiddle">');
}  
else  
{  
	$("#userID").removeClass('object_ok'); // if necessary
	$("#userID").addClass("object_error");
	$(this).html(msg);
}  
   
   });

} 
   
  }); 

}
else
{
$("#status").html('<font color="red">The userID should have at least <strong>4</strong> characters.</font>');
$("#userID").removeClass('object_ok'); // if necessary
$("#userID").addClass("object_error");
}

});

});

//-->
</SCRIPT>
<SCRIPT type="text/javascript">
<!--
/*
Credits: Bit Repository
Source: http://www.bitrepository.com/web-programming/ajax/userID-checker.html 
*/

pic1 = new Image(16, 16); 
pic1.src = "loader.gif";

$(document).ready(function(){

$("#email").change(function() { 

var usr = $("#email").val();

if(usr.length >= 4)
{
$("#status2").html('<img src="loader.gif" align="absmiddle"> Checking availability...');

    $.ajax({  
    type: "POST",  
    url: "checkemail.php",  
    data: "email="+ usr,  
    success: function(msg){  
   
   $("#status2").ajaxComplete(function(event, request, settings){ 

if(msg == 'OK')
{ 
        $("#email").removeClass('object_error'); // if necessary
	$("#email").addClass("object_ok");
	$(this).html(' <img src="tick.gif" align="absmiddle">');
}  
else  
{  
	$("#email").removeClass('object_ok'); // if necessary
	$("#email").addClass("object_error");
	$(this).html(msg);
}  
   
   });

} 
   
  }); 

}
else
{
$("#status2").html('<font color="red">The email should have at least <strong>4</strong> characters.</font>');
$("#email").removeClass('object_ok'); // if necessary
$("#email").addClass("object_error");
}

});

});

//-->
</SCRIPT>


<script type="text/javascript">
function AjaxFunction(email)
{
var httpxml;
try
{
// Firefox, Opera 8.0+, Safari
httpxml=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
httpxml=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
httpxml=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
function stateck() 
{
if(httpxml.readyState==4)
{
document.getElementById("msg").innerHTML=httpxml.responseText;

}
}
var url="checkemail.php";
url=url+"?email="+email;
url=url+"&sid="+Math.random();
httpxml.onreadystatechange=stateck;
httpxml.open("POST",url,true);
httpxml.send(null);
}
</script>

 

 

    <tr>
      <td width="200"><div align="right">email: </div></td>
      <td width="100"><input id="email" size="20" type="password" name="email" onBlur="AjaxFunction(this.value);"></td>
      <td width="400" align="left"><div id="status2"></div></td>
    </tr> 

 

 

checkemial.php

<?php


// This is a sample code in case you wish to check the userID from a mysql db table


     include('library/login.php');
     login();

    
    $sql_check = mysql_query("select email from user where email='".$email."'") or die(mysql_error());
    $email = $_POST['email'];

if(isSet($_POST['email']))
  {
  if (!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $email))
    {
      echo "<font color=red> Invalid email</font> \n";
    }
  elseif (mysql_num_rows($sql_check))
      {
        echo "<font color='red'>The e-mail ".$email." is already in use.</font> \n";
      }
    else
    {
      echo "OK";
    }



  }

?> 

 

 

Can someone could point me in the right direction???

Link to comment
https://forums.phpfreaks.com/topic/190156-checking-emial-for-format/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.