Saturday, July 15, 2023

Client side validation

 

Client side  validation

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="valid1.aspx.cs" Inherits="valid1" %>

 

 

<html >

<head runat="server">

    <title></title>

 

     <script language="javascript" type="text/javascript">

         function validationCheck()

         {

             var summary = "";

             summary += isvaliduser();

             summary += isvalidpassword();

             summary += isvalidConfirmpassword();

             summary += isvalidFirstname();

             summary += isvalidLastname();

             summary += isvalidEmail();

             summary += isvalidphoneno();

             summary += isvalidLocation();

 

             if (summary != "")

             {

                 alert(summary);

                 return false;

             }

             else

             {

                 return true;

             }

 

         }

         function isvaliduser() {

             var id;

             var temp = document.getElementById("<%=txtuser.ClientID %>");

             id = temp.value;

             if (id == "") {

                 return ("Please Enter User Name" + "\n");

             }

             else {

                 return "";

             }

         }

         function isvalidpassword() {

             var id;

             var temp = document.getElementById("<%=txtpwd.ClientID %>");

             id = temp.value;

             if (id == "") {

                 return ("Please enter password" + "\n");

             }

             else {

                 return "";

             }

         }

         function isvalidConfirmpassword() {

             var uidpwd;

             var uidcnmpwd;

             var tempcnmpwd = document.getElementById("<%=txtcnmpwd.ClientID %>");

             uidcnmpwd = tempcnmpwd.value;

             var temppwd = document.getElementById("<%=txtpwd.ClientID %>");

             uidpwd = temppwd.value;

 

             if (uidcnmpwd == "" || uidcnmpwd != uidpwd) {

                 return ("Please re-enter password to confrim" + "\n");

             }

             else {

                 return "";

             }

         }

         function isvalidFirstname() {

             var id;

             var temp = document.getElementById("<%=txtfname.ClientID %>");

             id = temp.value;

             if (id == "") {

                 return ("Please enter first name" + "\n");

             }

             else {

                 return "";

             }

         }

         function isvalidLastname() {

             var id;

             var temp = document.getElementById("<%=txtlname.ClientID %>");

             id = temp.value;

             if (id == "") {

                 return ("Please enter last name" + "\n");

             }

             else {

                 return "";

             }

         }

         function isvalidEmail() {

             var id;

             var temp = document.getElementById("<%=txtEmail.ClientID %>");

             id = temp.value;

             var re = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;

             if (id == "") {

                 return ("Please Enter Email" + "\n");

             }

             else if (re.test(id)) {

                 return "";

             }

 

             else {

                 return ("Email should be in the form ex:abc@xyz.com" + "\n");

             }

         }

         function isvalidphoneno() {

             var id;

             var temp = document.getElementById("<%=txtphone.ClientID %>");

             id = temp.value;

             var re;

             re = /^[0-9]+$/;

             var digits = /\d(10)/;

             if (id == "") {

                 return ("Please enter phone no" + "\n");

             }

             else if (re.test(id)) {

                 return "";

             }

 

             else {

                 return ("Phone no should be digits only" + "\n");

             }

         }

         function isvalidLocation() {

             var id;

             var temp = document.getElementById("<%=txtlocation.ClientID %>");

             id = temp.value;

             if (id == "") {

                 return ("Please enter Location" + "\n");

             }

             else {

                 return "";

             }

         }

</script>

 

</head>

<body>

    <form id="form1" runat="server">

 

 

    <table>

            <tr>

                <td>

                    Username</td>

                <td>

                    <asp:TextBox ID="txtuser" runat="server"></asp:TextBox>

                </td>

            </tr>

            <tr>

                <td >

                    Password</td>

                <td>

                    <asp:TextBox ID="txtpwd" runat="server"></asp:TextBox>

                </td>

            </tr>

            <tr>

                <td >

                    confirm password</td>

                <td>

                    <asp:TextBox ID="txtcnmpwd" runat="server"></asp:TextBox>

                </td>

            </tr>

 

            <tr>

                <td >

                    First name</td>

                <td>

                    <asp:TextBox ID="txtfname" runat="server"></asp:TextBox>

                </td>

            </tr>

            <tr>

                <td >

                    last name</td>

                <td>

                    <asp:TextBox ID="txtlname" runat="server"></asp:TextBox>

                </td>

            </tr>

            <tr>

                <td >

                    Emial Address</td>

                <td>

                    <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>

                </td>

            </tr>

            <tr>

                <td >

                    Phone number</td>

                <td>

                    <asp:TextBox ID="txtphone" runat="server"></asp:TextBox>

                </td>

            </tr>

            <tr>

                <td >

                    Location</td>

                <td>

                    <asp:TextBox ID="txtlocation" runat="server" Height="22px"></asp:TextBox>

                </td>

            </tr>

            <tr>

                <td >

                    &nbsp;</td>

                <td>

                    <asp:Button ID="btnsubmit" runat="server" Text="Submit" />

                </td>

            </tr>

            <tr>

                <td >

                    &nbsp;</td>

                <td>

                    &nbsp;</td>

            </tr>

        </table>

 

    </form>

</body>

</html>

 

 

 

 

 

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

 

public partial class valid1 : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

 

        btnsubmit.Attributes.Add("onclick", "javascript:return validationCheck()");

 

    }

}

No comments:

Post a Comment

GRIDVIEW ON ROW DATA BOUND EVENT

 Database Create  Student : roll , name , city , cost  Fix 6 Value  in Database Record  ====================================================...