Validation problem in javascript

Posted by Prabu_Spark under JavaScript on 1/16/2013 | Points: 10 | Views : 884 | Status : [Member] | Replies : 1
Hi sir,
I validate the mobileno by accepting only numeric in textbox. It's working fine in internet Explorer but it is not validated in
Mozilla firefox. Kindly give me the solution for this problem. I attached the code below for the reference.

Default3.aspx:
*******************************


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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script language="vbscript" type="text/vbscript">
function num()
if (window.event.keyCode>=48 and window.event.keyCode<=57) or (window.event.keyCode=44) then
window.event.keyCode=window.event.keyCode
else
window.event.keyCode=0
end if
end function
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Enter the Mobile No. "></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" MaxLength="10" onkeypress="num()" Width="119px"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Submit" />
</div>
</form>
</body>
</html>

With regards,
J.Prabu.
[Email:prbspark@gmail.com]



Responses

Posted by: Ranjeet_8 on: 1/16/2013 [Member] [MVP] Gold | Points: 25

Up
0
Down
Try this,

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript" language="javascript">
function isNumericKey(e) {
var charInp = window.event.keyCode;
if (charInp > 31 && (charInp < 48 || charInp > 57)) {
return false;
}
return true;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Enter the Mobile No. "></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" MaxLength="10" onkeypress="return isNumericKey(event);"
Width="119px"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Submit" />
</div>
</form>
</body>
</html>


Please Mark As Answer if this helps you

.

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response