Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Sign In
Not a member yet? Click here to register.

Email Problem

I have a registration form (not php-fusion related) that requires an email address. The problem I am having is that if the email address contains a period (.), there is an error that states it is not a valid address and the form is not submitted. The code in the validate.js file that is part of the registration form is as follows:


CodeDownload  
function isEmail(field, ErrorMsg) {
   var strMsg = "";
   var chAt = '@';
   var chDot = '.';
   var strEmailAddr = trim(field.value);
    if (strEmailAddr.length == 0) return true;
    if (strEmailAddr.indexOf(" ") == -1)
    {
    var iFirstAtPos = strEmailAddr.indexOf(chAt);
    var iLastAtPos = strEmailAddr.lastIndexOf(chAt);
    if (iFirstAtPos > 0 && iFirstAtPos < (strEmailAddr.length - 1) &&iFirstAtPos == iLastAtPos) {
       // look for '.' there must be at least one char between '@' and '.'
       var iDotPos = strEmailAddr.indexOf(chDot, iFirstAtPos + 1);
       if (iDotPos > (iFirstAtPos + 1) && iDotPos < (strEmailAddr.length -1)) return true;
    }
    }
    alert(ErrorMsg);
    field.focus();
    return false;
}



The code that processes the registration form also has the following code:

CodeDownload  
echo "<center><br><br><span style='font-size:16px; color:#840000;'><b>".$emailError."<a href='javascript:history.go(-1)'>Go Back and Redo!</a></b></span></center>\n";
exit;
} else if(!preg_match("/^[\w-]+[@]+[a-z]+\.+[a-z]*$/", $_POST['email'])) {
   //} else if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])) {
      $emailError = "Invalid email format. ";
      $email ="";
echo "<center><br><br><span style='font-size:16px; color:#840000;'><b>".$emailError."<a href='javascript:history.go(-1)'>Go Back and Redo!</a></b></span></center>\n";
exit;



What code needs to be adjusted and in which file does it need to be adjusted to fix this problem? Thanks in advance.
CodeDownload  
$re = '/[\w-.]+[@]+[a-z]+\.+[a-z]*/m';
$str = 'gmail.gmail.com@gmail.com
';

preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);

// Print the entire match result
var_dump($matches);

Thanks for your response Chan...where would I add/change the code you provided?

I just noticed the reference to gmail...the email addresses I am referencing are not necessarily from gmail.
Thread Information
Author
Posted In
Replies
3 posts
Views
119 times
Last Post
Last updated on 2 months ago
Related Threads
You can view all discussion threads in this forum.
You can start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You can download attachments in this forum.
Users who participated in discussion: afoster, Chan