Results 1 to 2 of 2

Thread: Textbox

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    784

    Textbox

    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

  2. #2
    Addicted Member MasterBlaster's Avatar
    Join Date
    Jul 2002
    Location
    Seattle
    Posts
    196
    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.
    "And most of the evils of society can, in fact, be cured through information. We have a society that has been disinformed and based on the disinformation has made irrational choices. And that's what I mean by 'ignorance.' People, who ordinarily might be smart, are deprived of the data by which to make a rational decision, don't have the data to do it."
    Frank Zappa

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width