Private Function IsTextInteger(target As TextBox) As Boolean
If Integer.TryParse(target.Text, Nothing) Then
If target.Text.Length = 4 Then Return True
Else
Return False
End If
End Function
check textbox if it has 4 integers
-
08-10-2022 - |
Question
I have tried using IsNumeric()
but it does not fulfill what I want to achieve.
I have a MaskedTextBox. 4-digits and - as PromptChar.
What I want is to trigger an event checkSomething()
when there is 4-digit combination.
Say, 0001 then it will get an event. But nothing will happen when there is still a - in it. (000- | -001 and so on)
If mtPig.Text has 4digits then
.....
Else
Solution
OTHER TIPS
Look at the MaskCompleted (http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.maskcompleted.aspx) and MaskFull properties.
MaskCompleted - all mandatory characters have been entered
MaskFull - all mandatory and optional characters have been entered
You could use the Validating event as @Vignesh has, or KeyPress if you want to do it keystroke by keystroke.