Anda di halaman 1dari 5

JAVASCRIPT VALIDATION CODING FOR NAME,EMAIL ID IN CORRECT AND PHONE

UP TO 10 DIGIT IN A VALID WAY

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

function validate()

      if (document.getElementById("<%=txtname.ClientID%>").value=="")

      {

                 alert("Name Feild can not be blank");

                 document.getElementById("<%=txtname.ClientID%>").focus();

                 return false;

             }

             if (document.getElementById("<%=txtEmail.ClientID %>").value == "") {

                 alert("Email id can not be blank");

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

                 return false;

             }

             var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-


z]\w*)+)$/;

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

             var matchArray = emailid.match(emailPat);

             if (matchArray == null) {

                 alert("Your email address seems incorrect. Please try again.");

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

                 return false;


             }

             if (document.getElementById("<%=txtphoneno.ClientID%>").value == "") {

                 alert("Sorry, the phone field is blank");

                 document.getElementById("<%=txtphoneno.ClientID%>").focus();

                 return false;

             }

             var re10digit = /^\d{10}$/

             if (document.getElementById("<%=txtphoneno.ClientID %>").value.search(re10digit)


== -1) {

                 alert("Please enter a valid 10 digit area code");

                 document.getElementById("<%=txtphoneno.ClientID %>").focus();

       

        return false;


 
 
 

      return true;

 }

</script>

Also in the submit button set as follows

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" OnClientClick="return


validate()" Text="submit" />

Create a new form ,name it and then on the feedback button to click of the form we are
doing
window opening

Below Content Place holder 1

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

    function validate() {

        window.open("feedback.aspx");

       

    }

     
 

</script>

on the corresponding button

<asp:Button ID="Button4" runat="server" 

                    Text="feedback" OnClientClick="validate()"

                     />

then to close window of that form on clicking submit do as follows in that form

Below Content Place holder 1

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

    function validate() {

        window.close("feedback.aspx");

       

    }

     
 

</script>
on the corresponding button

<asp:Button ID="Button4" runat="server" 

                    Text="feedback" OnClientClick="validate()"

                     />

Substring for category

   protected void txtitemname_TextChanged(object sender, EventArgs e)

    {

       

        string st= "select substring('" +txtitemname.Text  + "',1,3)";

        SqlCommand cmd = new SqlCommand(st , cn.con); 

        SqlDataReader dr = cmd.ExecuteReader();

        if (dr.Read())

        {

            txtitemcode.Text  = dr.GetValue(0).ToString();

        }

       

    }

Validation to be integer only

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


function check_float(e, field) {
if (!(((e.keyCode >= 48) && (e.keyCode <= 57)) || (e.keyCode == 46)))
{
alert("only digits are allowed");
e.keyCode = 0;
}
if (e.keyCode == 46) {
var part1 = new RegExp("\\.");
var ch = part1.exec(field);
if (ch == ".") {
alert("More than one decimal point not allowed");
e.keyCode = 0;
}
}
}

function TABLE1_onclick() {

</script>

Under page load

txtaccountno.Attributes.Add("onkeypress",
"check_float(event,document.getElementById('" + txtaccountno.ClientID +
"').value)");

Anda mungkin juga menyukai