---
title: "How to make a textbox which is only accept the numeric value in WPF"  
description: "How to make a textbox which is only accept the numeric value in WPF"  
author: "Anonymous User"  
published: 2013-07-18  
updated: 2013-07-18  
canonical: https://www.mindstick.com/forum/1318/how-to-make-a-textbox-which-is-only-accept-the-numeric-value-in-wpf  
category: "wpf"  
tags: ["wpf"]  
reading_time: 1 minute  

---

# How to make a textbox which is only accept the numeric value in WPF

Hello [Mindstick](https://yourviews.mindstick.com/view/84668/how-mindstick-is-used-for-marketing-purposes)!

I need to make a [textbox](https://www.mindstick.com/forum/12714/dynamic-textbox-in-gridview) in [wpf](https://www.mindstick.com/forum/304/wpf) [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) which is [accept](https://yourviews.mindstick.com/view/81278/we-have-to-accept-that-roger-federer-is-the-richest-one) only numeric value.

thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)

## Replies

### Reply by shreesh chandra shukla

Hi !try this

```
private void myTextBox_PreviewKeyDown(object sender, KeyEventArgs e)        {            switch(e.Key)            {                case Key.D0:                case Key.D1:                case Key.D2:                case Key.D3:                case Key.D4:                case Key.D5:                case Key.D6:                case Key.D7:                case Key.D8:                case Key.D9:                case Key.NumLock:                case Key.NumPad0:                case Key.NumPad1:                case Key.NumPad2:                case Key.NumPad3:                case Key.NumPad4:                case Key.NumPad5:                case Key.NumPad6:                case Key.NumPad7:                case Key.NumPad8:                case Key.NumPad9:                case Key.Back:                    break;                default:      e.Handled = true;                    break;            }        }
```


---

Original Source: https://www.mindstick.com/forum/1318/how-to-make-a-textbox-which-is-only-accept-the-numeric-value-in-wpf

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
