English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

3 answers

The above answer is not recommended, as Javascript does not belong to asp.net. ASP.net offers very simple solutions by just some simple clicks.

There are several solutions to your problem. The easiest way to do it is by the use of validationcontrols. Follow the instructions below:

- Open the aspx-page in "design"
- Display your toolbox.
- Click on "Validation"
- Drag & drop a RequiredFieldValidator
- Click with right mousebutton, demand "properties" of the RequiredFuildValidator
- "ControlToValidate" becomes the name of your textfield
- Select "ErrorMessage" and fill in "No digits allowed!"
- Select "ValidationExpression"
- Click on "..."
- Fill in [^0-9]*

This will eliminate all digits. Run your web form (aspx page) and you'll see that if you enter digits and push the submit button, a red message will appear on the location you placed the RequiredFieldValidator.

Good luck!

2006-12-27 00:02:40 · answer #1 · answered by stevevil0 3 · 0 1

ASP.NET does not do this by itself (although there are a few third-party controls that do input masking). You can, however, accomplish it using simple JavaScript and invoking it on the TextBox control:



In your code, simply write:

txtTextBoxId.Attributes _
.Add("onKeyDown", _
"return maskBox(event);")

This will work in IE, FF, Opera, and most others. For the few that don't understand it, it will just let them type anything; won't return an error. Sorry for the line breaks, Yahoo seems to be hiding code if I don't break it up.

Edit:

Also, it is important to note that you should never rely on client-side validations for important input. Always make sure to re-check on the server-side; even if the input masking works correctly, the user can always insert their own values into the postback header to break your site.

2006-12-26 23:02:51 · answer #2 · answered by Rex M 6 · 0 0

incredibly straight forward technique which will in no way fail this would be a trick unquestionably attempt { textbox1.text textile = convert.tointeger(cost) } capture(Exception ex) { tutor msg that valid integer isn't entered } you additionally can discover javascript and disable all keys different than integers I had the code yet cant discover it

2016-12-11 16:46:12 · answer #3 · answered by gagliano 4 · 0 0

fedest.com, questions and answers