Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
code is working fine for two textbox

but when i add thired varibale in my code so it is not working so plz tell that how to write this code

C#
Name = document.getElementById("txt_name").value;
            regno = document.getElementById("txt_reg_no").value;
            frmdate = document.getElementById("txt_fromdate").value;
            if ((Name == "") && (regno == "") && (frmdate == "") ) {
                alert("Enter either name or registration or date");
                return false;
            }

            else {

                var reg1 = new RegExp('^[a-zA-Z]+$');
                var reg2 = new RegExp('^[0-9a-zA-Z/-]+$');
                if ((Name != "") && (regno != "")) {
                    if (!reg1.test(Name)) {
                        alert("Invalid Name Entered");
                        return false;
                    }

                    if (!reg2.test(regno)) {
                        alert("Invalid Registration Enterd");
                        return false;
                    }

                }

                else {


                    if (Name == '') {

                        if (!reg2.test(regno)) {
                            alert("Invalid Registration Entered");
                            return false;
                        }

                    }
                    else {
                        if (!reg1.test(Name)) {
                            alert("Invalid Name Entered");
                            return false;
                        }
                    }
                }
            }
Posted
Comments
enhzflep 28-Jun-14 4:23am    
How about posting an SCCCE, rather than a simple snippet?
OriginalGriff 28-Jun-14 4:24am    
How would you expect us to know what "when i add thired varibale in my code so it is not working" *means* when we don't know what it is supposed to do? Or how you added it? Or what you found that "not working"?

Use the "Improve question" widget to edit your question and provide better information.

1 solution

JavaScript
if ((Name == "") && (regno == "") && (frmdate == "") ) {
   alert("Enter either name or registration or date");
   return false;
}

if ((Name != "") && !reg1.test(Name)) {
   alert("Invalid Name Entered");
   return false;
}
if ((regno!= "") && !reg2.test(regno)) {
   alert("Invalid Registration Entered");
   return false;
}
// do some validation for frmdate as above 
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900