troubleshooting Question

Easy Regexp question

Avatar of jjacksn
jjacksn asked on
3 Comments1 Solution200 ViewsLast Modified:
I can't figure out what i'm doing wrong here:

I'm trying to validate that a string is a valid integer, using this regular expression and C# code.

private static Regex _intPattern = new Regex( @"[-]?[0-9]+");
            public static bool IsValidInteger(string val)
                  Match match = _intPattern.Match( val );
                        return true;
                        return false;

but that will match anything that has a valid number in it.  I want to make sure there is only 1 match, and that the match is the entire string.  how should I do that?

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros