Click here to Skip to main content
15,913,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
function isNumberKey()
 {
    var key = window.event.keycode;
    if (key < 48 || key > 57) {
        return false;
    }
    else {
        return true;
    }
 }
 function IsAlpha() {
     var key = window.event.keycode;
     if ((key >= 65 && key <= 90) || (key >= 97 && key <= 122)) {
         return true;
     }
     else {
         return false;
     }
 }

XML
<tr>
                    <td align="right" style="width:20%">MOBILE NO.</td>
                    <td class="style3"><asp:TextBox ID="TXT_M_NO" class="txt" runat="server" onkeypress="return isNumberKey()" BackColor="lightyellow"></asp:TextBox>
                    </td>
                    <td colspan="2"></td>
               </tr>

XML
<tr>
                     <td align="right" class="style2" style="width:20%">
                     <span style="color:Red;">*</span> EMPLOYEE NAME </td>
                     <td class="style1"><asp:TextBox ID="TXTEMP_NAME" class="txt" runat="server" onkeypress="return IsAlpha()" BackColor="lightyellow"></asp:TextBox>
                     </td>
                    <td align="right" style="width:10%">LAST NAME</td>
                    <td><asp:TextBox ID="TxtLnm" class="txt" runat="server" onkeypress="return IsAlpha()" BackColor="lightyellow"></asp:TextBox>
                    </td>
                </tr>

These two function of validation is not working
please let me know how it will work
Posted
Comments
Richard C Bishop 18-Dec-13 13:44pm    
I don't think you need "return" before the javascript function call in your onkeypress event.

1 solution

Use an asp custom validator as follows:
ASP CustomValidator

CustomValidator.ClientValidationFunction Property

Besides client side, should also include server side validation as well.
 
Share this answer
 
v3

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