Q&A

Q1:I want to create a textbox that allows the user to enter only a certain type of input, such as numbers. How can I do this?
A1: In the BMI calculator example we examined in the previous hour, the user was prompted for weight and height. Clearly, these inputs must be numeric ones. As we saw, if the user enters some input like “Fred” as weight, it breaks the BMI calculator.

Therefore, you might think that an ideal solution would be to create a textbox into which the user can enter numbers only. Such masked textboxes, as they are called, are rarely, if ever, used on Web pages for a number of reasons.

First, while a masked textbox would prevent the user from entering something like “Fred” as weight, it would not prevent the user from entering ...

Get SAMS Teach Yourself ASP.NET in 24 Hours now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.