Regular expression for decimal number – Accepts only one digit after decimal point

Regex decimalRegex = new Regex(@”^\d+\.\d{1}$”);  // value must contains decimal point.
if (!decimalRegex.IsMatch(“YOUR VALUE”))
{
// Not valid
}
else
{
// Valid
}

Note: Not valid for .8 but valid for 0.8
Not valid: 8.    & valid: 8.0

References:

http://stackoverflow.com/questions/2491930/is-there-an-online-regexbuddy-like-regular-expression-analyzer

http://stackoverflow.com/questions/968825/regular-expression-for-decimal-number

http://stackoverflow.com/questions/1014284/regex-to-match-2-digits-optional-decimal-two-digits

http://stackoverflow.com/questions/308122/simple-regular-expression-for-a-decimal-with-a-precision-of-2

http://stackoverflow.com/questions/17418637/how-to-limit-only-two-digits-after-decimal-point-using-regex-validator

 

 

Advertisements
By Sriramjithendra Posted in C#.NET

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s