Jump to content

Sitholimela

New Members
  • Posts

    1
  • Joined

  • Last visited

Sitholimela's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Good Day, I have created a web page with more than 10 text boxes, i know how to use all validations from vs . now i want to apply validations using Javascript. here are my problems below. 1.For Email; I want a textbox to change border color to red if it is invalid email, belows it is what i have so far.. <script type="text/javascript"> ar emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i function checkmail(e){ var returnval=emailfilter.test(e.value) if (returnval==false){ alert("Please enter a valid email address.") e.select() } return returnval } </script> on the text box; <asp:TextBox ID="txtEmail" name="email" onClick="return checkmail(this.myemail)" runat="server" </asp:TextBox> 2.For Numbers This texbox will only allows numbers only ,I want a textbox to change border color to red if it is invalid input, belows it is what i have so far.. <script type="text/javascript"> function numeralsOnly(evt) { evt = (evt) ? evt : event; var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0)); if (charCode > 31 && (charCode < 48 || charCode > 57)) { alert("Enter numbers only in this field."); return false; } return true; } </script> on the text box; <asp:TextBox ID="txtFullName" onkeypress="return numeralsOnly(event)" runat="server"</asp:TextBox> 2.For Letters This texbox will only allows Letters only,I want a textbox to change border color to red if it is invalid input, belows it is what i have so far.. <script type="text/javascript"> function lettersOnly(evt) { evt = (evt) ? evt : event; var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0)); if (charCode > 31 && (charCode < 65 || charCode > 90) && (charCode < 97 || charCode > 122)) { alert("Enter letters only."); return false; } return true; } </script> on the text box; <asp:TextBox ID="txtFullName" onkeypress="return lettersOnly(event)" runat="server"</asp:TextBox> Thanks for your help....
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.