Enter Numeric Values

Posted by Priti2010 under JavaScript on 9/26/2012 | Points: 10 | Views : 1250 | Status : [Member] | Replies : 7
Please tell me how can i validate my textbox to enter first numeric character as 9 and rest any numeric value in javascript.

Thanks & Regards
Priti



Responses

Posted by: Hariinakoti on: 9/26/2012 [Member] Starter | Points: 25

Up
0
Down
Basicallly When we trying to validate a form some time we need numeric validation for textbox.

We can validate textbox by onkeypress event of the control By checking whether the keycode of the key pressed as the user types falls within the range of the number keys 48-57(i.e 0-9 and '.') ,if not belong to that range it will return false then it will disable the keypress action
function NumericValidation(eventObj)
{
var keycode;

if(eventObj.keyCode) //For IE
keycode = eventObj.keyCode;
else if(eventObj.Which)
keycode = eventObj.Which; // For FireFox
else
keycode = eventObj.charCode; // Other Browser

if (keycode!=8) //if the key is the backspace key
{
if (keycode<48||keycode>57) //if not a number
return false; // disable key press
else
return true; // enable key press
}
}

Thanks & Regards
Hari

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

Posted by: Hariinakoti on: 9/26/2012 [Member] Starter | Points: 25

Up
0
Down
Please Mark As Answer if u satisfy with my answer.It is useful to others

Thanks & Regards
Hari

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

Posted by: Muhsinathk on: 9/28/2012 [Member] Bronze | Points: 25

Up
0
Down
Nice explanation..

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

Posted by: Hariinakoti on: 9/28/2012 [Member] Starter | Points: 25

Up
0
Down
Thanq Ms.Muhsinathk

Thanks & Regards
Hari

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

Posted by: Muhsinathk on: 9/28/2012 [Member] Bronze | Points: 25

Up
0
Down
Welcome

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

Posted by: Jayakumars on: 9/28/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

try this Code

<asp:TextBox ID="numericTextBox" runat="server"></asp:TextBox>

<asp:RegularExpressionValidator ID="regularExpressionValidator" runat="server" ControlToValidate="numericTextBox" ValidationExpression="[9]+" ErrorMessage="Please enter a valid numeric value">
</asp:RegularExpressionValidator>

<asp:RequiredFieldValidator ID="requiredFieldValidator" runat="server" ControlToValidate="numericTextBox" ErrorMessage="Please enter a numeric value"></asp:RequiredFieldValidator>




Mark as Answer if its helpful to you

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

Posted by: Jayakumars on: 9/28/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
Please mark as answer if it helpful to you.


Mark as Answer if its helpful to you

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

Login to post response