I am currently doing a simple loading system, what I want to do is to check specific numbers for example these cellphone numbers are only for globe telecom (0915, 0916, 0917) and for smart telecom (0918, 0919, 0920, 0921). If the user checks on globe the number should be in globe telco number format, hence it won't save and prompt user "INVALID NUMBER".

Any help would be appreciated by me. thanks

What is the format of a globe telecom number? The regular expression for four digits is "\d(4}". I can be more precise if you are more specific about the format.

Edited 4 Years Ago by Reverend Jim

the cellphone numbers are 11 digits, prefix for globe telco are 0915, 0916, 0917
for example 09158923183. the 4-digit prefix means it's a globe number, hence, it's a smart number.

The regular expression for globe telecom numbers would be

"091[5|6|7]\d{7}"

091 followed by 5, 6 or 7, followed by seven digits. And to use the regular expression you include

Imports System.Text.RegularExpressions

Then to do the test

Dim pattern As String = "091[5|6|7]\d{7}"

If Regex.IsMatch(txtPhoneNumber.Text,pattern) Then
    'phone # is OK
Else
    'bad format
End If

Hi Jim, I tried to do it thru array, please do check my code,

        Dim globe() As String = {"091[5|6|7]\d{7}", "092[5|6|7]\d{7}"}
        Dim smart() As String = {"091[0|2|8|9]\d{7}", "092[0|1|8|9]\d{7}"}


        For Each valueOfSmart As String In smart
            If Regex.IsMatch(txtMobileNumber.Text, valueOfSmart) Then
                MsgBox("Smart Number")
            End If
        Next

        For Each valueOfGlobe As String In globe
            If Regex.IsMatch(txtMobileNumber.Text, valueOfGlobe) Then
                MsgBox("Globe Number")
            End If
        Next

If you see I can improve my code please tell me.

You don't need an array. You can use

Dim globe As String = "((0915)|(0916)|(0917))\d{7}"
Dim smart As String = "((0918)|(0919)|(0920)|(0921))\d{7}"

If Regex.IsMatch(txtMobileNumber.Text,globe) Then
    MsgBox("globe telecom number")
ElseIf Regex.IsMatch(txtMobileNumber.Text,smart) Then
    MsgBox("smart telecom number")
Else
    MsgBox("neither")
End If
This article has been dead for over six months. Start a new discussion instead.