number text box in asp.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MariaJC
    New Member
    • Feb 2007
    • 11

    number text box in asp.net

    Hi ,

    Can any one help me to check for numbers alone, in a text box using C#?
  • Hari Narayan Sharma
    New Member
    • Feb 2007
    • 7

    #2
    First of all, Add this to Top Line in .cs File,

    using System.Text.Reg ularExpressions ;


    Now use The Following Function:

    public static bool IsNumeric(strin g TextData)
    {
    string AllowChar = "[^0-9]";
    if(Regex.IsMatc h(TextData.Trim (),AllowChar))
    return false;
    else
    return true;
    }

    Comment

    • mshiva
      New Member
      • Feb 2007
      • 8

      #3
      By using validators u can easily did this one without writing any code.

      Comment

      • MariaJC
        New Member
        • Feb 2007
        • 11

        #4
        hi thanx for ur response. but i need alert if the user enters other than numbers.
        how can i create an alert for the text box as soon as its focus is lost??

        pls help

        Comment

        • MariaJC
          New Member
          • Feb 2007
          • 11

          #5
          Hi i am not able to get the control id of txtNumber1
          the value displayed is null
          how can i access this controls id in javascript?

          alert(document. getElementById( "txtNumber1 "));

          please help

          Comment

          Working...