JTUP JTUP - 6 months ago 47
Vb.net Question

How to validate a null value in a maskedtextbox phone number input mask

I want to check for null values. using this code below. i am still getting values in the textbox. The values i am getting in the textbox are "( ) -"...

If Text_Phone.Text IsNot "" Then
If BuildSqlFlag = True Then
BuildSql = BuildSql & " AND " & "Phone = " & Text_Phone.Text
Else
BuildSql = "Phone = " & Text_Phone.Text
End If
BuildSqlFlag = True
End If


i am not exactly sure what is needed from my code to be changed to i even tried the following:

If Text_Phone.Text IsNot "( ) -" Then


But that was no help.

Answer

Set the TextMaskFormat to exclude prompt and literals.

Text_Phone.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals

MaskFormat Enumeration

Then when you do Text_Phone.Text it will be equal to "" if it's empty.