Click here to Skip to main content
14,544,858 members
Rate this:
Please Sign up or sign in to vote.
See more:
how do i add email id validation code in this jsp page help me

how to add email id validation in between email code??

<script>
            function validate(){
                var username=document.form.ContactUserName.value;
                var email=document.form.ContactEmail.value;
                var passwd=document.form.ContactMessage.value;
                if(username==""){
                    alert("Enter Your Name!");
                    return false;
                }
                if(email==""){
                    alert("Enter Your E-Mail ID!");
                    return false;
                }
                if(passwd==""){
                    alert("Enter Your Message!");
                    return false;
                }
                if(passwd.toString().length > 1000){
                    alert("Your message contains more than 1000 chararacters.");
                    return false;
                }
                return true;
            }
Posted
Updated 8-May-13 2:25am
v3
Comments
max_nowak 8-May-13 8:24am
   
Is your question, how to validate your email address, whether it has the right format?
Rate this:
Please Sign up or sign in to vote.

Solution 1

Simple validation
<script language = "Javascript">

function emailcheck(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
}eles
 return true
}
   
v4
Rate this:
Please Sign up or sign in to vote.

Solution 2

Try this...Dude

function validation()
{
var mail=document.getElementById('txt_email').value;
var mail_pattern=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

if(mail=='')
{
document.getElementById('mesg_mail').innerHTML='Enter Your E-MailID';
return false;
}
else if(mail_pattern.test(mail)==false)
{
document.getElementById('mesg_mail').innerHTML='Enter a Valid E-Mail Id';
return false;
}
else
{
document.getElementById('mesg_mail').innerHTML='';
}
}
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100