14,695,085 members
See more:
Hi.

i have a text box which accepts numeric and decimal values. The max length of text box is 4.

So how can i check whether a text box contains a decimal point followed by a single digit at end of text box.

like ex:

if i have a value as 12.5 in the text box,then how can i check that a text box is containing a value ".5" at the end of textbox in C#

please provide me a solution.
Posted

## Solution 1

```string a = "12.5";

bool HasDecimal = a.Contains('.');

if (HasDecimal == true)
{
int i = a.IndexOf('.');
int j = a.Length;
int k = j - i;
a = a.Substring(i, k);
// now a contains only decimal value

}
else {
//no decimal
}```
v2
Member 10593922 14-Mar-14 2:41am

thank u for the reply. i will try to implement this... but what about the digit after decimal point how can i check that?
AndrewCharlz 14-Mar-14 3:13am

the out put will be ".5"

## Solution 2

Try this

```if(TestBox1.Text.Contains('.')&&TextBox1.Text.Split('.')[1].Length==1)
{
//code
}```
v2

## Solution 3

```private static readonly Regex OneDecimalCheck = new Regex(@"\.\d\$");
// ....
if (OneDecimalCheck.IsMatch(TheTextBox.Text))
{
// TheTextBox content Text ends with . followed by a digit.
}```

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 OriginalGriff 265 Patrice T 160 Sandeep Mewara 140 Rick York 95 k5054 95
 OriginalGriff 5,879 Richard Deeming 3,075 Richard MacCutchan 2,814 CPallini 2,002 Patrice T 1,600

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900