Text box should accept integer an float values

Posted by Chaithragm under C# on 3/30/2013 | Points: 10 | Views : 5827 | Status : [Member] | Replies : 4
How to validate the text box such that it should accept both integer and float values
2
2.4
vjh ->error enter only numbers




Responses

Posted by: Murugavelmsc on: 3/30/2013 [Member] Starter | Points: 25

Up
0
Down
http://www.dotnetfunda.com/forums/thread9248-how-to-allow-only-numeric-values-into-a-textbox.aspx

Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/

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

Posted by: Chaithragm on: 3/30/2013 [Member] Starter | Points: 25

Up
0
Down
Text box should accept both integer and float values

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

Posted by: Nadeemshaik on: 5/1/2013 [Member] Starter | Points: 25

Up
0
Down

write this code in textbox_PreviewTextInput event


private void txtBox1_PreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e)
{
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("^[.][0-9]+$|^[0-9]*[.]{0,1}[0-9]*$");
e.Handled = !regex.IsMatch((sender as TextBox).Text.Insert((sender as TextBox).SelectionStart, e.Text));
}

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

Posted by: Paraszalariya12 on: 5/2/2013 [Member] Starter | Points: 25

Up
0
Down
function numeric(keyCode) {

return ((keyCode >= 48 && keyCode <= 57)||(keyCode >=96 && keyCode <=104) || keyCode == 8 || keyCode == 9 || keyCode ==110)
}


and textbox

<asp:TextBox ID="txt_name" runat="server" onkeydown="return alphabates(event.keyCode);"

onpaste="return false;"></asp:TextBox>


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

Login to post response