472,951 Members | 2,234 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,951 software developers and data experts.

Need help with regex

Dim reg As New Regex("^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$")
Dim m As Match = reg.Match(txtIPAddress.Text)
If m.Success Then
'No need to do anything here
Else
MessageBox.Show("You need to enter a valid IP Address", "Error!",
MessageBoxButtons.OK, MessageBoxIcon.Hand)
txtIPAddress.Focus()
Return
End If


I need to match a IP addy on this and I would think this should match only a
x.x.x.x to xxx.xxx.xxx.xxx pattern yet it passes as a match when I input
192168121113

Any ideas what I am doing wrong here ?

Thanks,

Mike
Nov 21 '05 #1
2 1904
Michael,
"." matches any character except \n. To match a period you need to "escape"
it with a slash. "\." will match a period.

Try the following:

Const pattern As String = "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$"
Static reg As New Regex(pattern, RegexOptions.Compiled)
Dim m As Match = reg.Match(txtIPAddress.Text)
If m.Success Then
'No need to do anything here
Else
MessageBox.Show("You need to enter a valid IP Address",
"Error!", MessageBoxButtons.OK, MessageBoxIcon.Hand)
End If

Unless I need the Match object specifically, I normally use Regex.IsMatch
instead.

Something like:
Const pattern As String = "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$"
Static reg As New Regex(pattern, RegexOptions.Compiled)
If reg.IsMatch(txtIPAddress.Text) Then
'No need to do anything here
Else
MessageBox.Show("You need to enter a valid IP Address",
"Error!", MessageBoxButtons.OK, MessageBoxIcon.Hand)
End If

Hope this helps
Jay
"Michael R. Pierotti" <mr*@hafatel.com> wrote in message
news:uU**************@TK2MSFTNGP12.phx.gbl...
Dim reg As New Regex("^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$")
Dim m As Match = reg.Match(txtIPAddress.Text)
If m.Success Then
'No need to do anything here
Else
MessageBox.Show("You need to enter a valid IP Address", "Error!",
MessageBoxButtons.OK, MessageBoxIcon.Hand)
txtIPAddress.Focus()
Return
End If


I need to match a IP addy on this and I would think this should match only
a
x.x.x.x to xxx.xxx.xxx.xxx pattern yet it passes as a match when I input
192168121113

Any ideas what I am doing wrong here ?

Thanks,

Mike

Nov 21 '05 #2
Thank mate how did I miss that ? LOL

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uY**************@TK2MSFTNGP09.phx.gbl...
Michael,
"." matches any character except \n. To match a period you need to "escape" it with a slash. "\." will match a period.

Try the following:

Const pattern As String = "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$"
Static reg As New Regex(pattern, RegexOptions.Compiled)
Dim m As Match = reg.Match(txtIPAddress.Text)
If m.Success Then
'No need to do anything here
Else
MessageBox.Show("You need to enter a valid IP Address",
"Error!", MessageBoxButtons.OK, MessageBoxIcon.Hand)
End If

Unless I need the Match object specifically, I normally use Regex.IsMatch
instead.

Something like:
Const pattern As String = "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$"
Static reg As New Regex(pattern, RegexOptions.Compiled)
If reg.IsMatch(txtIPAddress.Text) Then
'No need to do anything here
Else
MessageBox.Show("You need to enter a valid IP Address",
"Error!", MessageBoxButtons.OK, MessageBoxIcon.Hand)
End If

Hope this helps
Jay
"Michael R. Pierotti" <mr*@hafatel.com> wrote in message
news:uU**************@TK2MSFTNGP12.phx.gbl...
Dim reg As New Regex("^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$")
Dim m As Match = reg.Match(txtIPAddress.Text)
If m.Success Then
'No need to do anything here
Else
MessageBox.Show("You need to enter a valid IP Address", "Error!",
MessageBoxButtons.OK, MessageBoxIcon.Hand)
txtIPAddress.Focus()
Return
End If


I need to match a IP addy on this and I would think this should match only a
x.x.x.x to xxx.xxx.xxx.xxx pattern yet it passes as a match when I input
192168121113

Any ideas what I am doing wrong here ?

Thanks,

Mike


Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Joe | last post by:
Hi, I have been using a regular expression that I don’t uite understand to filter the valid email address. My regular expression is as follows: <asp:RegularExpressionValidator...
2
by: Luhar | last post by:
After much scouring of information on Regular Expressions from books and the web, I've come up with the this handy little Regex to parse links from HTML: ...
1
by: hillcountry74 | last post by:
Hi, I'm stuck with this regular expression from past 2 days. Desperately need help. I need a regular expression that will allow all characters except these *:~<>' This is my code in...
9
by: jmchadha | last post by:
I have got the following html: "something in html ... etc.. city1... etc... <a class="font1" href="city1.html" onclick="etc."click for <b>info</bon city1 </a> ... some html. city1.. can repeat...
7
by: Extremest | last post by:
I am using this regex. static Regex paranthesis = new Regex("(\\d*/\\d*)", RegexOptions.IgnoreCase); it should find everything between parenthesis that have some numbers onyl then a forward...
15
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
3
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
I'm trying to learn regex but since I've spent way too much time on the following "simple" case, there's obviously something I'm missing. I need to find all occurrences of a specific...
8
by: Alexander Vasilevsky | last post by:
This code Regex ge = new Regex(""); string format = ge.Replace("8 kBit/s, 8,000 Hz, Mono", "_"); returns "8 kBit_s_ 8_000 Hz_ Mono" and I need "8_kBit_s_ 8_000_Hz_ Mono"
4
by: Danny Ni | last post by:
Hi, The following code snippet is causing CPU to max out on my local machine and production servers. It looks fine on Expresso though. Regex rgxVideo = new...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.