0
<script type='text/javascript' language="javascript">
function validate()
    {
        var error=0;
        var name=document.getElementById("name");
        var checkname =/^[a-zA-Z]+$/;
        var email= document.getElementById("email");
        var emailcheck = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
        var re_pass;


        if (name.value == "") {
            name.style.background = 'Yellow'; 
            error = 1;
            alert('enter user name!');
        } else if ((name.value.length < 5) || (name.value.length > 15)) {
            name.style.background = 'Yellow'; 
            error = 1;
            alert('name must be between 5 and 15 characters!');
        } else if (!checkname.test(name.value)) {
            name.style.background = 'Yellow'; 
            error = 1;
            alert('invalid name! must be alphabet!');
        } else {
            name.style.background = 'White';
        }


        if (email.value == "") {
            email.style.background = 'Yellow'; 
            error = 1;
            alert('enter email address!');
        } else if (!emailcheck.test(email.value)) {
            email.style.background = 'Yellow'; 
            error = 1;
            alert('invalid email address!');
        } else {
            email.style.background = 'White';
        }

        if (pass.value == "") {
            pass.style.background = 'Yellow';
            error =1;
            alert('enter your passward!');
        } else if ((pass.value.length < 4) || (fld.value.length > 15)) {
            pass.style.background = 'Yellow';
            error = 1;
            alert('passwerd  must be between 4 and 15 characters!');
        }

        if (re_pass.value == "") {
            re_pass.style.background = 'Yellow';
            error = 1;
            alert('enter your passward again!');
        }
        else if(pass.value!=re_pass.value){
            re_pass.style.background="yellow!";
            error=1;
            alert('both passward must be same!');
        }
        if(error=1)
            return false;
            else
            return true;
    }
</script>Inline Code Example Here
2
Contributors
2
Replies
20
Views
3 Years
Discussion Span
Last Post by Dervish1
0

thas my code. the problem is that the validation errors alert occur but form is also submitted either it is validated or not

0

First, line 61 is a typo: '=' is not a comparison, but rather an assignment. But whether or not it's correct, are you sure your calling function is interpreting the false return correctly?

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.