Link to home
Start Free TrialLog in
Avatar of Gizeh2000
Gizeh2000

asked on

Need a regular expression or similar to verify entered mobilenumbers in VB.NET!

Hello,

I need to write a regular expression or something similar that checks wether an entered mobile number is correct. Code is vb.net!
The numbers are all entered in one and the same textbox wich after clicking the submit button is verified by code and returns a boolean wether the number is correct or not.

The mobile number may also not contain letters and may not be empty and may not hold more than 17 characters including spaces.

Here are some examples of mobile numbers which are accepted and valid:

0031 6 12345678              (dutch mobile numbers)
0032 473 123456               (belgian mobile numbers)
0049 175 1234567             (German mobile numbers)

So basically for the dutch number that would be:
00<landcode><space><netnumber without 0><space><number>
00<31> <6> <12345678>                

belgian number :
00<landcode><space><netnumber without 0><space><number>
00<32> <473> <123456>

german number :
00<landcode><space><netnumber without 0><space><number>
00<49> <175> <1234567>

It doesnt have to be a regular expression but it would be great if it were. So long as the code works and does what it is supposed to do then thats alright with me.

Therefore I'm gonna give this question 400 points. Happy code solving fella's and dudettes.

Kind regards,
Gizeh




ASKER CERTIFIED SOLUTION
Avatar of riyazthad
riyazthad

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Fernando Soto
Hi Gizeh2000;

This should do what you need.

Imports System.Text.RegularExpressions

        ' Sample Data
        Dim input As String = "0032 473 123456"

        If Regex.Match(input, "^00\d\d\s[1-9]\d*\s[1-9]\d+$").Value.Length <= 17 Then
            MessageBox.Show("Cell number is valid")
        Else
            MessageBox.Show("Cell number is NOT valid")
        End If


Fernando
Avatar of Gizeh2000
Gizeh2000

ASKER

Hi Thad,

Works like a charm! Thanks for taking the time to write down these reg expressions. And sorry Fernando, Thad was first so, first come first served.

Kind regards,
Gizeh
Thanks Gizeh

Thad