Jump to content

Disabling input type (number / alpha / special char)

- - - - -

  • Please log in to reply
2 replies to this topic

#1
sAkura019

sAkura019

    Newbie

  • Members
  • Pip
  • 1 posts
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..

#2
cdg10620

cdg10620

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 389 posts
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. :)
-CDG10620
Software Developer

#3
gokuajmes

gokuajmes

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 518 posts
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




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users