Restrict user to enter numeric value in textbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SKS
    New Member
    • Oct 2006
    • 2

    Restrict user to enter numeric value in textbox

    hi all
    i would like to know how to restrict user from entering numeric value
    ina textbox..using C#
    if user try to enter text it shouldnt be allowed..
    i tried errror provider..
    but it doesnt met my requirement..
    thanks in advance for ur valuable reply
    let me know the best to do it

    urs
    SKS
    Last edited by SKS; Nov 10 '06, 01:17 PM. Reason: didnt mention the language
  • Akshay144
    New Member
    • Oct 2006
    • 5

    #2
    have u used any of the validators?

    Comment

    • nmsreddi
      Contributor
      • Jul 2006
      • 366

      #3
      hello

      if you are familar with java script then its better choice to use (web application)

      other wise you have write the code in codebehing using C# by using ASCII values verify the each key stroke value if the mach is success then do nothing

      if the condition fails have a popup(if windows pplication)


      try it out


      regards

      nmsreddi

      Comment

      • Attiq
        New Member
        • Mar 2008
        • 1

        #4
        H!
        To restrict user from different inputs you can use these fuctions:
        IsDigit
        IsHighSurrogate
        IsLetter
        IsLetterOrDigit
        IsLower
        IsLowSurrogate
        IsNumber
        IsPunctuation
        IsSeparator
        IsSurrogate
        IsSurrogatePair
        IsSymbol
        IsUpper
        IsWhiteSpace


        private void textBox1_KeyPre ss(object sender, KeyPressEventAr gs e)
        {
        if (Char.IsDigit(e .KeyChar) )
        { MessageBox.Show ("Bad Input");
        e.Handled = true; ;
        }
        }

        Comment

        • VijaySofist
          New Member
          • Jun 2007
          • 107

          #5
          Originally posted by SKS
          hi all
          i would like to know how to restrict user from entering numeric value
          ina textbox..using C#
          if user try to enter text it shouldnt be allowed..
          i tried errror provider..
          but it doesnt met my requirement..
          thanks in advance for ur valuable reply
          let me know the best to do it

          urs
          SKS
          Add the following code in the script side of your html text box control

          [CODE=htmlscript]onkeydown="if (window.event.k eyCode > 47 && window.event.ke yCode < 58){ return false; }"[/CODE]

          All The Best
          With Regards
          Vijay. R

          Comment

          • malav123
            New Member
            • Feb 2008
            • 217

            #6
            Hi,
            just write the following function in javascript for your requirement...
            [CODE=javascript]
            function noNumeric()
            {
            if( !isNaN(yourtext box.value))
            {
            alert("Numerics not allowed");
            return false;
            }
            }
            [/CODE]
            Last edited by malav123; Apr 11 '08, 01:57 PM. Reason: For proper format of code

            Comment

            Working...