Allow Only Enter Numbers or Digits in Textbox Using in C# Window Application

Allow Only Enter Numbers or Digits  in Textbox


Textbox Only Enter Allow Number Values Accepts  Character Values Not Acepted in C# Window Application.

                              DEMO




                                  C# CODING


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class MobileNumber : Form
    {
        public MobileNumber()
        {
            InitializeComponent();
        }

        private void txtMobileNumber_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (char.IsDigit(e.KeyChar) || char.IsControl(e.KeyChar))
            {
                e.Handled = false;
            }
            else
            {
                e.Handled = true;
            }
        }
    }
}




First - Add - New Window Form - Add TextBox  - Change Id 





Next - TextBox Property - Go To - Event - KeyPress Double Click







Next - Add Event - Click Mobile Coding







Next - Run [F5] - Does Not Accept - Character Only Number 











0 comments:

Post a Comment