<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

Recommended Answers

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?

Jump to Post

All 2 Replies

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

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?

Be a part of the DaniWeb community

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