How to check the zero value in the mask for entering the masked text number

I want to check for null values. using this code below. I am still getting the values ​​in the text box. The values ​​that I get in the text box 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'm not quite sure what is needed from my code that needs to be changed, I even tried the following:

If Text_Phone.Text IsNot "(   )   -" Then

But it did not help.

+4
source share
2 answers

Install TextMaskFormat to exclude tooltips and literals.

Text_Phone.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals

Maskformat enumeration

Then when you do Text_Phone.Text, it will be equal ""if it is empty.

+1
source

'' Confirm the phone number in this format: 999-999-9999

Imports System.Text.RegularExpressions
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, _
     ByVal e As System.EventArgs) Handles Button1.Click
        Dim phoneNumber As New Regex("\d{3}-\d{3}-\d{4}")
        If phoneNumber.IsMatch(TextBox1.Text) Then
            TextBox2.Text = "Valid phone number"
        Else
            TextBox2.Text = "Not Valid phone number"
        End If
    End Sub
End Class

'' Confirm the phone number in this format (999) 999-9999

Private Sub Button1_Click_1(sender As System.Object, _
 e As System.EventArgs) Handles Button1.Click
        Dim phoneNumber As New Regex("\(\d{3}\)\d{3}-\d{4}")
        If phoneNumber.IsMatch(TextBox1.Text) Then
            TextBox2.Text = "Valid phone number"
        Else
            TextBox2.Text = "Not Valid phone number"
        End If
End Sub
+1

All Articles