Regex that allows only whole numbers and decimal upto 2 places:

Hi,

The following code is about a regular expression that allows only whole numbers and decimal numbers only upto two places.



string s = "1234.45";
Regex r = new Regex("^\\d+\\.*?\\d{0,2}$");
Match m = r.Match(s);
if (m.Success)
{
Response.Write("TRUE");
}
else
{
Response.Write("False");
}


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: