Here is a solution to such a problem.
Following is a regular expression I wrote will validate 0 to i number of integers and 0 to f number of fractional points.
string sTest = @"^\d{0," + i + @"}\.\d{0," + f + "}$";
string i = iNumericLength.ToString();
string f = iDecimalPoints.ToString();
string sTest = @"^\d{0," + i + @"}\.\d{0," + f + "}$";
Regex ex = new Regex(sTest);
string st = txtEnteredValue.Text;
if (!ex.IsMatch(st))
{
}MessageBox.Show("This is a decimal field which supports max. of " + i + " numbers and max. of " + f+ " decimal numbers.");
No comments:
Post a Comment