Re: Regex expression for numeric value with length check

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Good morning Wdudek,

Based on the MSDN article mentioned by Bob, I write this regular expression
for your reference. It checks a string contains all numbers and is between
1~9 characters long.

\b([0-9]{1,9})\b

Please let us know whether it works for you or not.

Have a very nice day!

Regards,
Jialiang Ge (jialge@xxxxxxxxxxxxxxxxxxxx, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@xxxxxxxxxxxxxx

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within 2
business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


"eBob.com" <fakename@xxxxxxxxxxxxxxxx> wrote in message
news:uOy%23zTJOJHA.3876@xxxxxxxxxxxxxxxxxxxxxxx
I think that this is what you need:
http://msdn.microsoft.com/en-us/library/3206d374.aspx

Also, get a FREE product called Expresso from UltraPico.

Good Luck, Bob


"wdudek" <wdudek@xxxxxxxxxxxxxxxx> wrote in message
news:EE3DD8A1-CDB3-497B-BF78-64A6E53D0FF3@xxxxxxxxxxxxxxxx
Hi,

I am horrible at regular expressions so I'm hoping this might be an
easy
one for someone else. I need to perform a check that a string contains
all
numbers and is between 1 and 9 characters long. I have the first part
working, but can't get the length check to work.

This is what I am using to perform the check to see if the string is all
numeric. ^[0-9]*$

However I can't get it to match anything when I have tried to check the
length as well. Also I need to do this in one expression, i.e. I can't
make 1
call to check for numeric values and a second to check for length.

Thanks,
Bill

P.S. This is what I have been using to test this.


static void Main(string[] args)
{
//string input = "00767140001575333";
string input = "00767140";
Regex r = new Regex("^[0-9]*$");


bool result = r.IsMatch(input);
Console.WriteLine(result.ToString());

Console.WriteLine("hit a key");
Console.ReadKey();


}




.



Relevant Pages

  • Re: Logging off
    ... public static Process RunExecutable(string exe, string userName, string password) ... // So will set the working directory to the current directory. ... The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Regex expression for numeric value with length check
    ... So 18 characters of numeric values would not be valid even though it ... It checks a string contains all numbers and is ... Microsoft Online Community Support ... initial response from the community or a Microsoft Support Engineer ...
    (microsoft.public.dotnet.framework)
  • Re: Regex expression for numeric value with length check
    ... Microsoft Online Community Support ... You can send feedback directly to my manager at: ... initial response from the community or a Microsoft Support Engineer ... I need to perform a check that a string contains ...
    (microsoft.public.dotnet.framework)
  • Re: best method of querying
    ... I also noticed that the "Act" variable here seems hasn't been declared. ... I've try building the same code and got the same result and the "Operator '+' cannot be applied to operands of type 'string' " error does pointing to the "Act.Trim" which should be of method call syntax such as Act.Trim ... We welcome your comments and suggestions about how we can improve the support we provide to you. ... The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Get regular expression
    ... own tree structure. ... Expression compares a string character-by character, ... regular expression solution, which was about as close as one could get to ... the structure of the hierarchy can be inferred by using ...
    (microsoft.public.dotnet.languages.csharp)