Click to See Complete Forum and Search --> : Textbox
Winanjaya
Nov 14th, 2003, 12:11 AM
Dear The Expert,
I need to set the textbox to allow numeric input only and it automatically display with thousand separator and 2 decimal symbol.. how to do this?
Please help
Thanks
Winanjaya
MasterBlaster
Nov 14th, 2003, 11:38 AM
There are a few ways to do it. there are validator controls that will check tha value of your text box client side or you can validate on the server side using regular expressions.
public static bool Validate(string DirtyString, string RegularExpresion)
{
bool passed = true;
System.Web.HttpContext curr = System.Web.HttpContext.Current;
string currcell = curr.Server.HtmlEncode(DirtyString);
currcell = currcell.Trim();
if (passed == PassedFilter(currcell,RegularExpresion))
{
return true;
}
else
{
return false;
}
}
public static bool PassedFilter(string DirtyString, string FilterExp)
{
string cleanstring = "";
foreach (Match charMatch in System.Text.RegularExpressions.Regex.Matches(DirtyString, FilterExp))
{
cleanstring = cleanstring + charMatch;
}
if (cleanstring.Length == DirtyString.Length)
{
return true;
}
else
{
return false;
}
}
This is the server side way. Pass the string you want to validate and the regular expression to validate against it.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.