473,626 Members | 3,343 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regex Number Check

Should not the following return False if s="255xxxxyyy "? It seems to return
True.

Regex.IsMatch(s , "[0-9]")
--
Dennis in Houston
Nov 21 '05 #1
5 2263
Yes, it should return false.

'-- Check for number
Regex.IsMatch(s , "^\d+$")
"Dennis" <De****@discuss ions.microsoft. com> wrote in message
news:4E******** *************** ***********@mic rosoft.com...
Should not the following return False if s="255xxxxyyy "? It seems to
return
True.

Regex.IsMatch(s , "[0-9]")
--
Dennis in Houston

Nov 21 '05 #2
?Thanks for reply. Which one should return false, the one you send
(Regex.IsMatch( s, "^\d+$") or mine (Regex.IsMatch( s, "[0-9]")? Mine returns
true in VB.net 2003.

"Dr Screwup" wrote:
Yes, it should return false.

'-- Check for number
Regex.IsMatch(s , "^\d+$")
"Dennis" <De****@discuss ions.microsoft. com> wrote in message
news:4E******** *************** ***********@mic rosoft.com...
Should not the following return False if s="255xxxxyyy "? It seems to
return
True.

Regex.IsMatch(s , "[0-9]")
--
Dennis in Houston


Nov 21 '05 #3
Mine should be true for this: s = "1293" and false for this s= "255xxxxyyy .
Yours will return true for anything except this s="ABC" (anything without a
number).
"Dennis" <De****@discuss ions.microsoft. com> wrote in message
news:0A******** *************** ***********@mic rosoft.com...
?Thanks for reply. Which one should return false, the one you send
(Regex.IsMatch( s, "^\d+$") or mine (Regex.IsMatch( s, "[0-9]")? Mine
returns
true in VB.net 2003.

"Dr Screwup" wrote:
Yes, it should return false.

'-- Check for number
Regex.IsMatch(s , "^\d+$")
"Dennis" <De****@discuss ions.microsoft. com> wrote in message
news:4E******** *************** ***********@mic rosoft.com...
> Should not the following return False if s="255xxxxyyy "? It seems to
> return
> True.
>
> Regex.IsMatch(s , "[0-9]")
> --
> Dennis in Houston


Nov 21 '05 #4
Thanks. I guess I really had it wrong. I got the Regex string from one of
the previous notes on this newsgroup.

"Dr Screwup" wrote:
Mine should be true for this: s = "1293" and false for this s= "255xxxxyyy .
Yours will return true for anything except this s="ABC" (anything without a
number).
"Dennis" <De****@discuss ions.microsoft. com> wrote in message
news:0A******** *************** ***********@mic rosoft.com...
?Thanks for reply. Which one should return false, the one you send
(Regex.IsMatch( s, "^\d+$") or mine (Regex.IsMatch( s, "[0-9]")? Mine
returns
true in VB.net 2003.

"Dr Screwup" wrote:
Yes, it should return false.

'-- Check for number
Regex.IsMatch(s , "^\d+$")
"Dennis" <De****@discuss ions.microsoft. com> wrote in message
news:4E******** *************** ***********@mic rosoft.com...
> Should not the following return False if s="255xxxxyyy "? It seems to
> return
> True.
>
> Regex.IsMatch(s , "[0-9]")
> --
> Dennis in Houston


Nov 21 '05 #5
Dennis,
Should not the following return False if s="255xxxxyyy "? It seems to
return
True.

Regex.IsMatch(s , "[0-9]") If you try it, you will find it returns True, as you are looking for a
single digit 0 thru 9 anyplace in the input string. The string "255xxxxyyy "
contains 3 matches, the first 2, the first 5 & the second 5.

While: Regex.IsMatch(s , "^\d+$") Will return false for "255xxxxyyy ", as you are looking for the beginning of
the string "^", followed by one or more digits "\d+", followed by the end of
the string "$".

For example, try the following code for both patterns:

Imports System.Text.Reg ularExpressions

Const theFirstPattern As String = "[0-9]"
Const theSecondPatter n As String = "^\d+$"
Const input As String = "255xxxxyyy "

Dim theFirstRegex As New Regex(theFirstP attern)
Debug.WriteLine (theFirstRegex. IsMatch(input), "first is match")
For Each aMatch As Match In theFirstRegex.M atches(input)
Debug.WriteLine (aMatch.Value, aMatch.Index.To String())
Next

Dim theSecondRegex As New Regex(theSecond Pattern)
Debug.WriteLine (theSecondRegex .IsMatch(input) , "second is match")
For Each aMatch As Match In theSecondRegex. Matches(input)
Debug.WriteLine (aMatch.Value, aMatch.Index.To String())
Next

The following site provides a good overview of regular expressions:

http://www.regular-expressions.info/

While this site provides the syntax specifically supported by .NET:

http://msdn.microsoft.com/library/de...geElements.asp

Hope this helps
Jay

"Dennis" <De****@discuss ions.microsoft. com> wrote in message
news:4E******** *************** ***********@mic rosoft.com... Should not the following return False if s="255xxxxyyy "? It seems to
return
True.

Regex.IsMatch(s , "[0-9]")
--
Dennis in Houston

Nov 21 '05 #6

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

Similar topics

9
3065
by: Christ | last post by:
Hi there, i'm trying to make a regex, but it ain't working. In just one regex expression I want to check a password that must meet following requirements: - at least 6 characters long - at least one letter (doesn't matter where in te string) - at least one number (doesn't matter where in te string) (those are no prob) - excluding 0, o, O, i, I, l, L, 1 (to prevent confusion about
8
2977
by: Johnny | last post by:
I need to determine whether a text box contains a value that does not convert to a decimal. If the value does not convert to a decimal, I want to throw a MessageBox to have the user correct the value in the text box. I have the following code but when the user enters a decimal value the Regex.IsMatch catches it (ex. 250.50 should be allowed, but 250.50.0 should not). My code is as follows: if( ! Regex.IsMatch( tboxQtyCounted.Text,...
4
9740
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a numeric value according to an arbitrary regular expression.
9
4573
by: Tim Conner | last post by:
Is there a way to write a faster function ? public static bool IsNumber( char Value ) { if (Regex.IsMatch( Value.ToString(), @"^+$" )) { return true; } else return false; }
8
1818
by: vbmark | last post by:
I'm new to RegEx in vb.net so I'm not sure how to do this. I want to know if a string contains two minus signs "-". If there are two then I want it to return TRUE. I also need to know if the string contains two plus signs "+". Should this be a seperate RegEx or can one RegEx check for both signs? Thanks!
3
2110
by: jg | last post by:
I made a mistake somewhere in my vb code and I look, check and read against the articles and help on regex, I still can't find the mistake I made. I know my test string and the test patterns works, because I used on a vs. script to check. I also believe I foolwed followed the regex syntax for dotnet. here is the source code for the function and testing Public Function regtest(ByVal StringIn As String, ByVal patrn As
24
14404
by: cassetti | last post by:
Here's the issue: I have roughly 20 MS excel spreadsheets, each row contains a record. These records were hand entered by people in call centers. The problem is, there can and are duplicate phone numbers, and emails and addresses even person names. I need to sift through all this data (roughly 300,000+ records and use fuzzy logic to break it down, so that i have only unique records.
7
1675
by: MattMika | last post by:
Can anyone point out the problem with this? The commented regex var and if statement dont work and break the GroupName check when uncommented. I tested the AccessCodeRegxp with preg_match and it seems to work fine, it just wont here. Any pointers would be great. <script language="javascript"><!-- function check_form() { var error = 0; var error_message = "<?php echo JS_ERROR; ?>"; var customers_group_name =
1
1749
by: TumurS | last post by:
Hi! I need to parse an input string. The string must consist of 1, 2 or 3 float numbers separated with blanks: Regex r = new Regex(@"^\s*(?<x>+)(\s+(?<y>+)(\s+(?<z>+))*)*\s*$", RegexOptions.ExplicitCapture); Match m = r.Match(intput_str);
0
8272
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, 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...
0
8205
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,...
0
8713
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, 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...
0
7206
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6126
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4094
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...
1
2632
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
1
1817
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1516
bsmnconsultancy
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...

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.