Search code examples
.netvb.netmaskedtextbox

check textbox if it has 4 integers


I have tried using IsNumeric() but it does not fulfill what I want to achieve.

I have a MaskedTextBox. 4-digits and - as PromptChar.

enter image description here

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

  • 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