0

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(){}


    }

Edited by Dani: Formatting fixed

4
Contributors
8
Replies
33
Views
4 Years
Discussion Span
Last Post by stbuchok
0

length is a number not a string.

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

0

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

0

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>
-1

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

0

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.

0

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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.