如何检查文本框中是否包含小数点后跟文本框中的单个数字 [英] how to check whether a textbox contains a decimal point followed by a single digit in the textbox at the end
本文介绍了如何检查文本框中是否包含小数点后跟文本框中的单个数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨。
我有一个接受数字和小数值的文本框。文本框的最大长度为4.
那么如何检查文本框是否包含小数点后跟文本框末尾的单个数字。
如前:
如果我在文本框中输入值为12.5,那我怎么能检查文本框在C文本框的末尾是否包含值.5#
请给我一个解决方案。
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.
推荐答案
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
}
试试这个
Try this
if(TestBox1.Text.Contains('.')&&TextBox1.Text.Split('.')[1].Length==1)
{
//code
}
private static readonly Regex OneDecimalCheck = new Regex(@"\.\d
这篇关于如何检查文本框中是否包含小数点后跟文本框中的单个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文