hi friend,
in my project for example one textbox i need to type only numbers not the characters if i type the chars it will show
wat shall i do
my idea is it can be done in textbox_keypress event
can anybody give a solution
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
paul danielPosted Mar 2, 2010, 2:19 AM
Dim Counter As Byte
Dim IsNumber As Boolean
IsNumber = False
For Counter = 0 To 9
If Chr$(KeyAscii) = Trim(Counter) Then IsNumber = True
Next
If Not IsNumber Then MsgBox ("That is not a number.")
End Sub
Naresh KodumuriPosted Feb 24, 2010, 4:44 AM
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57) )
return false;
return true;
}
write this function onkeypress="return isNumberKey(event)"
Hirendra SisodiyaPosted Feb 24, 2010, 4:29 AM
kiran kumarPosted Feb 24, 2010, 2:53 AM
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace keypress
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.textBox1.KeyPress += new KeyPressEventHandler(textBox1_KeyPress);
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if(char.IsLetter(e.KeyChar))
{
e.Handled = true;
MessageBox.Show("enter numeric value");
}
}
}
}
MARK THE ANSWER IF IT HELPS YOU