i have textbox loan. in that i want to type only numbers not characters.
loan 1000.
i am creating application in vb.net using csharp.
how to validate.please send the code.
rds,
Narasiman P
D
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Satyapriya NayakRank #47 · 31.5K reputationPosted Jul 2, 2012, 10:46 PM EDT
Try this...
For Type only number in a textbox
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (!System.Text.RegularExpressions.Regex.IsMatch(e.KeyChar.ToString(), "\\d+"))
e.Handled = true;
}
}
}
Thanks
Mahesh ChandRank #1 · 393.4K reputationPosted Jul 2, 2012, 11:09 PM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 3, 2012, 12:55 AM EDT
Are you use window application or web application?
if you use window application then you can also use regex string "^[0-9]*(\.)?[0-9]+$"
it also validate decimal number.
And for web application you can use java script for same.
Please refer
http://www.codeproject.com/Articles/11006/TextBox-which-accepts-only-numbers
http://www.c-sharpcorner.com/uploadfile/tadas/numerictextbox12062005220207pm/numerictextbox.aspx
hope this will help you.