Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

Disabling input type (number / alpha / special char)


  • Please log in to reply
2 replies to this topic

#1 sAkura019


    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 07 February 2011 - 01:34 PM

may i know the snippet for disabling any number input, letter input or character input in asp.net?

hmm, what i want is when a user presses a key, if it's not needed, the key typed shouldn't show. hmm, for example, i want to input numbers only, special characters and letters shouldn't be enabled when i press them. same goes for the other types of input..
  • 0

#2 cdg10620


    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 344 posts
  • Programming Language:C#, JavaScript, PL/SQL, Transact-SQL, VBScript, Others

Posted 09 February 2011 - 05:58 AM

I'm assuming you're talking about input for a TextBox. If you want to do this on the client then you will most likely need to write a javascript function that doesn't allow certain things to be typed. Otherwise, you can use a RegEx (Regular Expression) validator on the textbox and when the form is submitted, if it doesn't meet the RexEx requirements it will give an error and ask the user to change the value. If you use the RegEx Validator and don't want the user to see the postback you should put the form in an update panel.

Let me know if you have any other questions. :)
  • 0
Software Developer

#3 gokuajmes


    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 483 posts

Posted 13 February 2011 - 09:01 PM

Regular Expression Controls in Validation Tab of visual Studio are used for this purpose drop the code in html view and try it by changing the control to validate property
                                            <asp:RegularExpressionValidator ID="rgvFirstName" runat="server" ControlToValidate="first name textbox ID"
Display="Dynamic" SetFocusOnError="True" ValidationExpression="^[a-zA-z0-9 ]{10,20}$"
Text="Hello you typed wrong" ErrorMessage="Hello">

it accepts a-z, A-Z , 0 -9 upto 20 characters should be minimum of 10 characters
  • 0

Also tagged with one or more of these keywords: asp.net

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download