Sitholimela Posted August 22, 2013 Share Posted August 22, 2013 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+)$/ifunction 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.... Quote Link to comment https://forums.phpfreaks.com/topic/281459-emailnumbers-and-letters-validations/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.