hereis my code the html is on http://cdpn.io/rzcAu

/**************************************************************************
validation
***************************************************************************/

/*********validation Variables************/
var Email = document.getElementsByName("Email");
var Password = document.getElementsByName("Password"); 
var firstName = document.getElementsByName("FirstName"); 
var secondName = document.getElementsByName("SecondName");
var Captcha = document.getElementsByName("Captcha");
var name = document.getElementsByName("Name"); 
var Subject = document.getElementsByName("Subject"); 
var Message = document.getElementsByName("Message"); 

/*********validation Code************/



    function email_validation(){
        if (Email.length == ""){
            alert("Empty field");
            } 
             if ((Email.length < 5) && (Email < "@" ) &&(Email < ".")){
               alert("invalid format");
            }

        }
        function name_validation(){
            if(name.length === ""){
                alert("value not entered");
                if(name === number){
                    alert("invalid format");
                    }
                }
            }
        function captcha_validation(){
            if(Captcha.length === ""){
                alert("value not entered");
                }
            }
        function password_validation(){
            if(Password.length === ""){
                alert("value not entered");
                }
            }
        function firstName_validation(){
            if(firstName.length === ""){
                alert("value not entered");
                }
            }
        function secondName_validation(){
            if(secondName.length === ""){
                alert("value not entered");
                }
            }
        function subject_validation(){
            if(subject.length === ""){
                alert("value not entered");
                }
            }
        function subject_validation(){}


    }

You may want to be a little more specific. What do you expect? What is happening? What is the problem?

Member Avatar for stbuchok

length is a number not a string.

=== means that you are comparing both the value and the type, in your case both are wrong.

the problem is i dont know how to do validation its my first time doing it so im trying to validate
the form elements on the link please have a look at the code and tell me how i can do the validation

Member Avatar for Rahul47

You are using too much code for validation. As you mentioned you "Don't Know ?". So you want us to do it for you or help you figure out problem ?

If you want us to write it for you, then help yourrself by learning from scratch.

BTW if you ever heard of Regular Expressions then you can use it and its just two lines of code.

Here is a simple example for E-mail validation. You can modify it for others too. Help yourself

<html>
<head<title> E-Mail ID Validation</title></head>
<body>

<br><br>E-Mail ID:<input type="text" id="eid"/>
<input type="button" id="btnEID" value="Ok" onclick="validation()"/>

<script>

function validation()
{
    var email;
    var valid=/^[a-z0-9._]+@[a-z]+\.[a-z]+$/;
    email=document.getElementById("eid").value;
    var result=valid.test(email);
    if(result)
    {
        alert("Valid e-mail ID.")
    }
    else
    {
        alert("Invalid e-mail ID.")
    }
}
</script>
</html>

best practice says you cant use regular expressions to validate email because there isnt a perfect way to validate email usint them

Member Avatar for Rahul47

No offence but may i know which best practice? And second thing I have tested that code personally many times and also cross referenced online, that sounds perfect. Check if that is true with you too.
You just have to design Regular Expression for other things.

best practice says you cant use regular expressions to validate email because there isnt a perfect way to validate email usint them

Nor is there with any other method.

Member Avatar for stbuchok

The Regex Rahul wrote is considerably more accurate than what you wrote. I would suggest learning about Regex and JavaScript before you actually try writing anything else.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.