|
-
Aug 19th, 2008, 09:00 PM
#1
Thread Starter
Fanatic Member
RegExp
I am getting an error. I am attempting to convert a phone number with () and - to the 10 digit format. Also, I would like 7 digit numbers converted to 10 also, but I think I can handle that once I get this going. Anyways, let me know if you have any tips. Thanks!
Error:
Code:
Error 1 Overload resolution failed because no accessible 'New' accepts this number of arguments. C:\Documents and Settings\User\My Documents\Visual Studio 2008\Projects\JeffComputersPOS1\JeffComputersPOS1\frmPreTicket.vb 34 14 JeffComputersPOS1
I got the example from:
http://www.4guysfromrolla.com/webtech/031302-1.shtml
vb Code:
Function get10DigitPhoneNumber(ByVal strUnformattedPN As String) As String
'Create a regular expression object
Dim re
re = New System.Text.RegularExpressions.Regex 'RegExp was the example, but it did not work either
'System.Text.RegularExpressions
'Specify the pattern
re.Pattern = "(\d{3})(\d{3})(\d{4})"
'Use the replace method to perform the formatting
Dim strFormattedPN
Return re.Replace(strUnformattedPN, "($1) $2-$3")
End Function
I use VB .NET 2022. Currently developing StudyX educational software, PlazSales POS system and Yargis a space ship shooter game.
-
Aug 19th, 2008, 09:13 PM
#2
Re: RegExp
The error is telling you exactly what is wrong. The Regex class has two accesible constructors:
Regex(pattern as String)
Regex(pattern as String, options as RegexOptions)
The compiler is telling you that you are attempting to use a constructor that doesn't exist. Notice that IntelliSense shows you the overloaded methods after you type the first "(" after Regex. You'll see these two options there.
-
Aug 25th, 2008, 11:36 AM
#3
Thread Starter
Fanatic Member
Re: RegExp
This does not seem to be working. Maybe I should change the expression? I just want the 7 or 10 digits returned. I want the - and () removed.
Example phone numbers:
(314) 333-4444
314-333-44444
vb Code:
Function get10DigitPhoneNumber(ByVal strUnformattedPN As String) As String
'Create a regular expression object
Dim re As New System.Text.RegularExpressions.Regex("(\d{3})(\d{3})(\d{4})")
're = New System.Text.RegularExpressions.Regex("(\d{3})(\d{3})(\d{4})") 'RegExp was the example, but it did not work either
'System.Text.RegularExpressions
'Specify the pattern
're.Pattern = "(\d{3})(\d{3})(\d{4})"
'Use the replace method to perform the formatting
'Dim strFormattedPN
Return re.Replace(strUnformattedPN, "($1) $2-$3")
End Function
I use VB .NET 2022. Currently developing StudyX educational software, PlazSales POS system and Yargis a space ship shooter game.
-
Aug 25th, 2008, 11:52 AM
#4
Re: RegExp
do you just want to reformat phone numbers?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 25th, 2008, 11:55 AM
#5
Re: RegExp
try this:
vb Code:
Dim testStr As String = "(314) 333-4444"
testStr = Regex.Replace(testStr, "\(|\)", "")
testStr = Regex.Replace(testStr, " ", "-")
MsgBox(testStr)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 25th, 2008, 11:55 AM
#6
Thread Starter
Fanatic Member
Re: RegExp
Yes.
 Originally Posted by .paul.
do you just want to reformat phone numbers?
I use VB .NET 2022. Currently developing StudyX educational software, PlazSales POS system and Yargis a space ship shooter game.
-
Aug 25th, 2008, 11:57 AM
#7
Thread Starter
Fanatic Member
Re: RegExp
I also want to just take the 1st 7 or 10 digits based on what they provided. That is why I was thinking a Regex could be helpful, or at least good practice 
 Originally Posted by .paul.
try this:
vb Code:
Dim testStr As String = "(314) 333-4444"
testStr = Regex.Replace(testStr, "\(|\)", "")
testStr = Regex.Replace(testStr, " ", "-")
MsgBox(testStr)
I use VB .NET 2022. Currently developing StudyX educational software, PlazSales POS system and Yargis a space ship shooter game.
-
Aug 25th, 2008, 12:03 PM
#8
Re: RegExp
are you trying to take the numbers from a text file, and then reformat them?
post your text file.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 25th, 2008, 12:31 PM
#9
Thread Starter
Fanatic Member
Re: RegExp
No, users are entering the phone numbers into a web form and I want to make sure they get formatted nice into the database. Is there an easy way to apply an data entry mask on a ASP page like with VB Forms? Thanks!
 Originally Posted by .paul.
are you trying to take the numbers from a text file, and then reformat them?
post your text file.
I use VB .NET 2022. Currently developing StudyX educational software, PlazSales POS system and Yargis a space ship shooter game.
-
Aug 25th, 2008, 12:53 PM
#10
Re: RegExp
 Originally Posted by rex64
No, users are entering the phone numbers into a web form and I want to make sure they get formatted nice into the database. Is there an easy way to apply an data entry mask on a ASP page like with VB Forms? Thanks!
You can use a TextBox and a RegularExpressionValidator. The Validator has "U.S. Phone Number" as one of its standard expressions.
http://msdn.microsoft.com/en-us/libr...validator.aspx
-
Aug 25th, 2008, 05:13 PM
#11
Thread Starter
Fanatic Member
Re: RegExp
Yes, but I want the user to be able to type their number easily. I was hoping they could type it and Microsoft would add the () and - automatically, and then just give me the digits when I need them. Is this possible?
 Originally Posted by nmadd
I use VB .NET 2022. Currently developing StudyX educational software, PlazSales POS system and Yargis a space ship shooter game.
-
Aug 26th, 2008, 10:52 AM
#12
Re: RegExp
try this. it'll accept the numbers in any of the formats you mentioned + return just the numbers
vb Code:
Dim testStr As String = TextBox1.Text
Dim rx As New Regex("^(\(\d{3}\)|\d{3})?( |-)?\(?\d{3}\)?( |-)?\(?\d{4}\)?$")
MsgBox(Regex.Replace(rx.Match(testStr).Value, "\(|\)| |-", ""))
Last edited by .paul.; Aug 26th, 2008 at 01:36 PM.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|