Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
February 09, 2012, 04:05:00 PM

Pages: [1]   Go Down
  Print  
Author Topic: email content checker not working  (Read 1735 times)
durangod
Galactic Royalty
*****
Offline Offline

Posts: 203


« on: March 08, 2010, 12:53:22 PM »

removed as code did not work
see below
 
« Last Edit: March 09, 2010, 05:14:11 PM by durangod » Logged
MrPhil
Berserker Poster
*****
Offline Offline

Posts: 5083



« Reply #1 on: March 08, 2010, 03:47:42 PM »

Is your registration form named "FrmRegister", and it has a (text) field named "txtEmail"?

The old code asks if the index of character '@' (.value.indexOf) is -1 (not found), and likewise for '.' not found. When you gave an email address without @ or . , was it not seen? What was in the alert() call -- it should be
Code:
alert("Your email address is invalid");
or something similar. Then it should put "focus" on the email input field. Did any of this happen?

Your code is (assuming you have the right hierarchy of form and field names) checking for any spaces, and popping up an alert if there are (does it?). Then it checks for the lack of @ and . , and gives an alert popup if so.

My guess is that you've got the wrong hierarchy of objects: something other than document.FrmRegister.txtEmail. Maybe your form is within something else that's named? You might try printing out the value:
Code:
alert("address: "+document.FrmRegister.txtEmail.value);
in the Javascript, and see if you see what you just entered.
Logged

durangod
Galactic Royalty
*****
Offline Offline

Posts: 203


« Reply #2 on: March 08, 2010, 05:49:40 PM »

thanks bud yeah that is the name of the function call and  that helped alot, i was trying to see what was working with this and what was not working, what was happening is that some of the call was functioning but not all of it.  

this helped me tons thanks so much, i got it working by removing what didnt work and placing in some alt code to shift the var and check it.  

works great but i have a new challenge... if you want i will start a new thread bud


im trying to capture only .com .net .ca and .org in my email string  as i only want to accept popular email extensions, this will help me cut down on the trashy junk emails ..


this is what i have so far but im not getting the structure correct as i do not know of another way to do this other than an array, and i have never writen an array and checked it with the indexOf function.

here iswhat i have it all works great accept the last part where i split the email extentions, and im stuck bigtime i dont know the format here. And i dont know how to just take and say check bemail array for one of those values
Code:

var emailext:Array = new Array();
bemail.mail(".com");
bemail.mail(".net");
bemail.mail(".ca");
bemail.mail(".org");



if (email.length <= 5)
      alert("email addresses must be more than 5 characters long");
   else if(email.indexOf(' ') >= 0)
      alert("email addresses cannot have spaces in them");
   else if (email.indexOf('@') == -1)
      alert("valid email address must have an @ in it");
   else if (email.indexOf('.') == -1)
     alert("valid email address must contain a . in it");

This is the part im stuck on bud, below, i changed it to bmail so i would have a new var to look at
Code:
 var searchIndex:int = bemail.indexOf(ARRAY=".com,.net,.ca,.org");
if(searchIndex == -1)
       alert("valid email address must contain one of the following .com,.net,.ca,.org");
 
i also know im not checking the actual input of email on the array part im just checking the array, now im really lost

can i do something like this would it be easier to just an || statement  and not even use the array
Code:
else if (email.indexOf('.com') || ('.net') ||  yedayada  == -1)
     alert("valid email address must contain .com .net  .org .ca");
« Last Edit: March 09, 2010, 10:17:02 AM by durangod » Logged
durangod
Galactic Royalty
*****
Offline Offline

Posts: 203


« Reply #3 on: March 08, 2010, 07:55:15 PM »

good news  Applause looks like im getting closer but not quite there yet

im trying this

      
Code:
atcom = email.indexOf('.com')
         atnet = email.indexOf('.net')
         atca = email.indexOf('.ca')
         atorg = email.indexOf('.org')

 if(atcom == -1 || atnet == -1 || atca == -1 || atorg == -1)
                   {
              alert("valid email addresses must contain .com .net .org or .ca");
                    }
« Last Edit: March 09, 2010, 10:14:16 AM by durangod » Logged
durangod
Galactic Royalty
*****
Offline Offline

Posts: 203


« Reply #4 on: March 08, 2010, 08:09:00 PM »

with that code above if i have an email address of 12345@45.com it shows me the address on the print that it is in fact 12345@45.com useing the address display, but it still gives me the error for no .com in the string, not there just yet mmmm still working dangit lol
Logged
MrPhil
Berserker Poster
*****
Offline Offline

Posts: 5083



« Reply #5 on: March 09, 2010, 08:09:17 AM »

       atcom = email.indexOf('.com')
         atnet = email.indexOf('.net')
         atca = email.indexOf('.ca')
         atorg = email.indexOf('.org')

 if(atcom == -1 || atnet == -1 || atca == -1 || atorg == -1)
                   {
              alert("valid email addresses must contain .com .net .org or .ca");
                    }

Code:
if (atcom == -1 && atnet == -1 && atca == -1 && atorg == -1)
would give you the error message if none of those extensions are found. Your current code will always see at least three of them as -1 and reject the address.

Note that instead of email.indexOf('.com'), which will "pass" an address such as spam@mail.com.cn, you might want to use email.substr(-4,4) == '.com' (returning true or false). This is limited to looking at the last N characters of the string.
Logged

durangod
Galactic Royalty
*****
Offline Offline

Posts: 203


« Reply #6 on: March 09, 2010, 08:41:38 AM »

thanks so much phil, i have changed accordingly but that section is still not working.  all the rest of it is fine, but it is not processing the the .com part of it, it catches the @ and the . and the space, but its not checking the .com ext var.. not sure why, i have moved that section around a bit from top to bottom to dif places but still not processing it...  here is how it looks so far, ill keep playing with it, it has to be a format issue, im not putting stuff in the right place is what im thinking ...  

here is the whole function that is called..
Code:
var xmlHttp
function toggle_email(email)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="user_availability.php";
url=url+"?email="+email;

//url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=Changed;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
var atcom = email.substr(-4,4) == '.com';
var atnet = email.substr(-4,4) == '.net';
var atca = email.substr(-4,4) == '.ca';
var atorg = email.substr(-4,4) == '.org';

                  
   {  

       if (atcom == -1 && atnet == -1 && atca == -1 && atorg == -1)
                     {              
                alert("valid email addresses must contain one of the following extensions .com .net .org or .ca");                
                    }
    else if (email.length <= 4)
                   {
               alert("email addresses must be minimum 5 characters long");
                   }
   else if(email.indexOf(' ') >= 0)
                   {
              alert("email addresses cannot have spaces in them");
                   }
   else if (email.indexOf('@') == -1)
                     {
               alert("valid email address must have an @ in it");
                    }
   else if (email.indexOf('.') == -1)
                   {
              alert("valid email address must contain a . in it");
                    }  
     }

}

{/code}


UPDATE just tested the atcom value and it is in fact false so the var are being loaded correctly and i changed the math to look for false instead of -1 but still not working
« Last Edit: March 09, 2010, 10:10:00 AM by durangod » Logged
MrPhil
Berserker Poster
*****
Offline Offline

Posts: 5083



« Reply #7 on: March 09, 2010, 09:57:25 AM »

Code:
var atca = email.substr(-3,3) == '.ca';
since it's only a two letter TLD.

Code:
if (!atcom && !atnet && !atca && !atorg)
since at* is now true or false. If any of the at* entries are true, the whole statement goes false.

Don't forget that you are merely popping up an "alert" box, and not setting any flags or other code to indicate that the email address is bad and needs to be re-entered. With your current code (as fixed above), you should get the alert popup, but otherwise nothing is done to mark "bad" email addresses (or, conversely, "good" ones -- your function doesn't return anything).

You have an extra { and } around the statements checking the email validity. Did you forget something?

P.S. Use [code] tags around code, so the indentation etc. doesn't get screwed up.
Logged

durangod
Galactic Royalty
*****
Offline Offline

Posts: 203


« Reply #8 on: March 09, 2010, 11:04:00 AM »

ok thanks bud, ok i think i fixed all the code in the thread to be inserted in code tags, sorry about that,

i am also going to add return false; to each check

i found the problem, i used the w3 schools try it function and the -4 is not working, its not starting from the end its starting from the beginning, thats why even if i have .com it still gives the message..

im trying to read up on how to get the substr to start at the rear because the -4 does not

in my test i ran the code as it is and i used the string 123456.com   and -4,4 results in 1234 and it should be .com   so i think i saw somewhere an example of using substr with the lastIndexOf that can be used to set it at the last, not sure where i saw it listed

UPDATE i have been reading and testing all kinds of functions and im starting to think that since the email input is such a variable in length and having to first strip the var down to find the last 4 using several dif functions together, would it be easier to just have the input as just the email like test@yahoo and let the member select their ext from a select box then add that to the email string.  
« Last Edit: March 09, 2010, 01:15:49 PM by durangod » Logged
MrPhil
Berserker Poster
*****
Offline Offline

Posts: 5083



« Reply #9 on: March 09, 2010, 01:00:55 PM »

That's interesting. It says right here in my Javascript reference that string.substr(-N,L) should return L characters starting N characters from the end (-1 being the last character). You did type in substr and not substring, didn't you?
Logged

durangod
Galactic Royalty
*****
Offline Offline

Posts: 203


« Reply #10 on: March 09, 2010, 01:09:16 PM »

yeah phil i read the same thing on numerious sites, your right thats what it says but the result is not what it says

please read my update on my prev post please, i wonder if that would be easier...

if you want to see what i mean about the result go to


http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_lastindexof

and clear out whats in the box and post the below in it and it will come back 1234

Code:
<html>
   <body>
      <script type="text/javascript">
         
var b = '12345678.com'
var grab = (b.substr(-4,4));         
         document.write (grab);
 

      </script>
   </body>
</html>
Logged
MrPhil
Berserker Poster
*****
Offline Offline

Posts: 5083



« Reply #11 on: March 09, 2010, 03:44:27 PM »

I just pasted that code into the w3schools site, and it came back.... .com

I'm on Firefox 3.6. What browser are you using?

Just tried it with Chrome... nothing displays on the right!
Just tried it on IE6... 1234 displays on the right!

It sounds like different browsers implement this differently. What you might do is get the index of ".", grab the stuff to the right, repeat until no more "." and hopefully that's the TLD that's remaining. If something as simple as .substr() doesn't work across browsers, I don't know if a "last index" will work.

You might want to pursue the proper way to code this in the Javascript board.
Logged

durangod
Galactic Royalty
*****
Offline Offline

Posts: 203


« Reply #12 on: March 09, 2010, 04:25:12 PM »

yeah im using ie8, just another downside to lack of standardization on the browers grrrrrrr....  i really appreciate your help bud...

ill check the javascript board just out of curiosity but i have changed my method...

i have 5 radio buttons one for each.  .com .net. .ca .org .biz  

i going to tackle this by taking the value of the radio button and pasting it on the end of the email def name
for example
they input  mytest@yahoo  they select their ext and i put it together  input + radio
at first i thought that was an easier way...

but omg now i cant get the value from the radio button , i have tried several things to grab this value and cant find it...


here is what i have bud, what name holds the value so i can pass it..



Code:
<form name="radioemail">
<input type="radio" name="chkmailext" value=".com" checked />.com &nbsp;
<input type="radio" name="chkmailext" value=".net" />.net &nbsp;
<input type="radio" name="chkmailext" value=".org" />.org &nbsp;
<input type="radio" name="chkmailext" value=".biz" />.biz &nbsp;
<input type="radio" name="chkmailext" value=".ca" />.ca &nbsp;
</form>
<script type="text/javascript">
for (i=0;i<document.radioemail.chkmailext.length;i++)
{
      if (document.radioemail.chkmailext[i].checked)
      {
             rbgroup_value = document.radioemail.chkmailext[i].value;
      }
}
</script>

ok so if i want to say $myext = Huh?? what do i put to get the value
« Last Edit: March 09, 2010, 04:36:01 PM by durangod » Logged
durangod
Galactic Royalty
*****
Offline Offline

Posts: 203


« Reply #13 on: March 09, 2010, 05:05:29 PM »

ok i found the value  it should have been var rbgroup_value   i just changed the var to rbgroup and called that and it works, now that i have a value string i can use it.... 

and on to the next issue with this change,   wow sometimes i really wonder about stuff, just when you think we are so far advanced in computers and functions the simplest little task takes alll day lol   

phil i really appreciate your help bud so much..
Logged
durangod
Galactic Royalty
*****
Offline Offline

Posts: 203


« Reply #14 on: March 10, 2010, 02:37:40 PM »

i got it working thanks so much, had to go back to my roots to do it lol
Logged
Pages: [1]   Go Up
  Print  
 
Jump to: