Check if TextBox contents are Numeric  
Author Message
Mirific201201





PostPosted: Windows Forms General, Check if TextBox contents are Numeric Top

I have a text box which will contain numbers (mobile numbers) and these will be delimited by comma's as shown below: -

07845123123, 07845321321, 07845123456

When the user clicks on a button I want to check that the contents of the textbox only contains numbers and comma's and doesn't start with a comma.

What would people recommend as the best way to handle this type of validation

Thanks & Regards



Windows Forms15  
 
 
cgraus





PostPosted: Windows Forms General, Check if TextBox contents are Numeric Top

As the numbers are too big for int.TryParse, I'd say you want to write a KeyPress event handler that sets Handled to true if Char.IsControl and Char.IsDigit are false, and the character typed is not a ,.