Dim reg As New Regex("^\d{1,3} .\d{1,3}.\d{1,3 }.\d{1,3}$")
Dim m As Match = reg.Match(txtIP Address.Text)
If m.Success Then
'No need to do anything here
Else
MessageBox.Show ("You need to enter a valid IP Address", "Error!",
MessageBoxButto ns.OK, MessageBoxIcon. Hand)
txtIPAddress.Fo cus()
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 2 1945
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.Co mpiled)
Dim m As Match = reg.Match(txtIP Address.Text)
If m.Success Then
'No need to do anything here
Else
MessageBox.Show ("You need to enter a valid IP Address",
"Error!", MessageBoxButto ns.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.Co mpiled)
If reg.IsMatch(txt IPAddress.Text) Then
'No need to do anything here
Else
MessageBox.Show ("You need to enter a valid IP Address",
"Error!", MessageBoxButto ns.OK, MessageBoxIcon. Hand)
End If
Hope this helps
Jay
"Michael R. Pierotti" <mr*@hafatel.co m> wrote in message
news:uU******** ******@TK2MSFTN GP12.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(txtIP Address.Text) If m.Success Then 'No need to do anything here Else MessageBox.Show ("You need to enter a valid IP Address", "Error!", MessageBoxButto ns.OK, MessageBoxIcon. Hand) txtIPAddress.Fo cus() 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
Thank mate how did I miss that ? LOL
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:uY******** ******@TK2MSFTN GP09.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.Co mpiled) Dim m As Match = reg.Match(txtIP Address.Text) If m.Success Then 'No need to do anything here Else MessageBox.Show ("You need to enter a valid IP Address", "Error!", MessageBoxButto ns.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.Co mpiled) If reg.IsMatch(txt IPAddress.Text) Then 'No need to do anything here Else MessageBox.Show ("You need to enter a valid IP Address", "Error!", MessageBoxButto ns.OK, MessageBoxIcon. Hand) End If
Hope this helps Jay
"Michael R. Pierotti" <mr*@hafatel.co m> wrote in message news:uU******** ******@TK2MSFTN GP12.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(txtIP Address.Text) If m.Success Then 'No need to do anything here Else MessageBox.Show ("You need to enter a valid IP Address", "Error!", MessageBoxButto ns.OK, MessageBoxIcon. Hand) txtIPAddress.Fo cus() 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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 id="valValidEmail"
runat="server"
ControlToValidate="txtEmail"
ValidationExpression="^(+)(\.+)*@(+)(\.+)*(\.{2,4})$"
|
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:
<a\s+href(?:\s+)?=(?:\s+)?+(.?+)+(?:\s+)?>(.*?)</a>
It works quite well at extracting the url and title of a link from an anchor
tag, with one major problem--if the anchor tag includes other attributes
after the HREF= attribute, such as TITLE= or TARGET=, it doesn't consider it
a...
|
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 VB.Net-
|
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 lot of times here....
Requirement:
-------------------
I want to get the value of "href" i.e "city1.html" by searching "city1"
between the <a</atag. Please note that "city1" can repeat lot of
|
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 slash then some numbers. For some reason I am not
getting that. It won't work at all in 2.0
| |
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
|
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 non-whitespace character sequence in a
string, but only if it occurs somewhere within a set of parentheses and only
if it's a whole word. Assuming the sequence to be found is the word "the"
and the string to be searched is as follows, the only matches should...
|
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"
|
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
Regex(@"<embed(\s++\s*=\s*(""*""|'*'|*))*\s+src=\s*(""|')?http://www.g4tv.com/i?sv3?/(?<videokey>\d+)(""|')?(\s++\s*=\s*(""*""|'*'|*))*\s*(/\s*>|>\s*</embed>)",
RegexOptions.IgnoreCase);
string strBody = "<embed name=\"VideoPlayer\"
src=\"http://localhost/lv3/26757\" width=\"480\"...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |