Your HostICan Community  


Go Back   Your HostICan Community > Programming & Design > Javascript / Java Applets

Javascript / Java Applets Are you a JavaScript guy? Do you need help with JavaScript? This is the place to talk about anything related to Java.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-06-2009, 10:15 AM
mren mren is offline
Junior Member
 
Join Date: Feb 2009
Posts: 1
Default email validation

Hi all, I need from simple and effective code for email validation.

Thanks in advance
Reply With Quote
  #2  
Old 03-06-2009, 10:58 AM
BigJON BigJON is offline
Member
 
Join Date: Jan 2009
Posts: 89
Default Re: email validation

This script check for a period "." character anywhere after the 3rd character in the string
Code:
function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
   }
If anyone knows a simple way, let it show.
Reply With Quote
  #3  
Old 03-07-2009, 06:38 AM
lnxpower lnxpower is offline
Junior Member
 
Join Date: Dec 2008
Posts: 5
Default Re: email validation

There is no doubt use of JavaScript is the most successful method for email validation
HTML Code:
<script language = "Javascript">
function echeck(str) {
        var at="@"
        var dot="."
        var lat=str.indexOf(at)
        var lstr=str.length
        var ldot=str.indexOf(dot)
        if (str.indexOf(at)==-1){
           alert("Invalid E-mail ID")
           return false
        }
        if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
           alert("Invalid E-mail ID")
           return false
        }
        if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
            alert("Invalid E-mail ID")
            return false
        }
         if (str.indexOf(at,(lat+1))!=-1){
            alert("Invalid E-mail ID")
            return false
         }
         if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
            alert("Invalid E-mail ID")
            return false
         }
         if (str.indexOf(dot,(lat+2))==-1){
            alert("Invalid E-mail ID")
            return false
         }
         if (str.indexOf(" ")!=-1){
            alert("Invalid E-mail ID")
            return false
         }
          return true                    
    }
function ValidateForm(){
    var emailID=document.frmSample.txtEmail
    if ((emailID.value==null)||(emailID.value=="")){
        alert("Please Enter your Email ID")
        emailID.focus()
        return false
    }
    if (echeck(emailID.value)==false){
        emailID.value=""
        emailID.focus()
        return false
    }
    return true
 }
</script>
Function echeck is used to verify if the given value is a possible valid email address. This function thus simply makes sure the email address has one (@), at least one (.). It also makes sure that there are no spaces, extra '@'s or a (.) just before or after the @. It also makes sure that there is at least one (.) after the @.
Function ValidateForm is used to make sure that the email field is not blank and that it is a valid email address on form submission.
Reply With Quote
  #4  
Old 03-11-2009, 09:31 AM
cech's Avatar
cech cech is offline
Member
 
Join Date: Feb 2009
Posts: 83
Default Re: email validation

This code make 100% checking for properly typed email address:
HTML Code:
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;
   }
}
There is a simple form who call the function above:
HTML Code:
<form id="form_id" method="post" action="action.php" onsubmit="javascript:return validate('form_id','email');">
   <input type="text" id="email" name="email" />
   <input type="submit" value="Submit" />
</form>
Reply With Quote
Reply

Tags
email, validation

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 03:31 PM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.

Copyright © 2003 - 2008 HostICan. All Rights Reserved.