473,394 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 1931
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.