Trouble with C# and regular expressions
Hi, I am trying to use regular expression to check if a string is a number and I do not want leading zeros so "123" is legal but "0123" is not and I am using the following:
Regex objNaturalPattern = new Regex("[1-9][0-9]*");
This works fine detecting if it is a number or alpha but it always gives me true for leading zeros, how can I make the zeros in front give me a false?
Thanks
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Mike GoldRank #50 · 30.6K pointsPosted Feb 21, 2007, 2:37 PM EST
Regex exp = new Regex("^[1-9][0-9]*");
Bjarni3 pointsPosted Feb 22, 2007, 12:49 AM EST