Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-11-09
4
Medium Priority
?
369 Views
Last Modified: 2008-02-01
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




0
Comment
Question by:Gizeh2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
riyazthad earned 1600 total points
ID: 17907722
Gizeh,

You can do it using reg expression. ou can check return value whether true or false.

For  dutch number :
        regex.Match(txtBox.Text,"^00\d{2}\x20[1-9]\x20\d{8}$").Success  
For  belgian number
        regex.Match(txtBox.Text,"^00\d{2}\x20[1-9]{3}\x20\d{6}$").Success  
For  german
        Regex.MatchtxtBox.Text, "^00\d{2}\x20[1-9]{3}\x20\d{7}$").Success

This will return TRUE if it is valid phone number.

I hope this will work out.

Thad
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 17911793
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
0
 

Author Comment

by:Gizeh2000
ID: 17928900
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
0
 
LVL 6

Expert Comment

by:riyazthad
ID: 17929632
Thanks Gizeh

Thad
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question