1

I have a credit card number text box which i want it to automatically insert spaces every 4 digits as the user types in the credit card number. how can i achieve that(in an elegant way if there is)? i am thinking if regular expressions can achieve it?

icube
  • 2,578
  • 1
  • 30
  • 63
  • 3
    You don't need regular expressions to for a simple count. Handle the KeyDown event and validate each key stroke. Insert a space if needed. – paparazzo Aug 13 '13 at 16:19
  • If the numbers are separated if the norm not to have 4 separate text boxes with 4 digits in each? – Fraser Aug 13 '13 at 16:20
  • Check this link http://forums.asp.net/t/1824550.aspx/1. You can achive this with javascript or jquery with keydown event – Jasti Aug 13 '13 at 16:22

2 Answers2

5

you can try using the MaskedTextBox from the

http://wpftoolkit.codeplex.com/wikipage?title=MaskedTextBox

to specify the format of the input

COLD TOLD
  • 13,513
  • 3
  • 35
  • 52
2

Try using a MaskedTextBox from the WPF Toolkit.

<wpfx:MaskedTextBox Mask="0000 0000 0000 0000" />

Tutorial Link

JeremiahDotNet
  • 910
  • 4
  • 9