Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Format textbox for number with 2 decimals
Message
 
 
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB 9.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01597155
Message ID:
01597226
Views:
31
>>>>What is a simple way to format an ASP.NET textbox for a number where user would enter the labor hours (e.g. 1.0, 2.25, 10.50 and so on).
>>>>When I add to the ASP.Textbox type="number" it would not allow a decimal.
>>>>What am I missing?
>>>>TIA
>>>>
>>>>UPDATE: Found this page with fairly simple javascript to allow only numbers with decimals.
>>>>
>>>>http://www.dotnetspark.com/kb/5510-accept-only-numeric-and-decimal-values-textbox.aspx
>>>
>>>Couple of thoughts:
>>>You could make this more generic by binding to all number types by using '$('input[type="number"]').----'
>>>You probably still need validation (user can, for example, paste in a value). Maybe a regex pattern:
<input type="number" step="0.01" pattern="^\d+(\.)\d{2}$" required/>
(That's limiting to 2 decimal places which may not be what you want)
>>
>>Strange thing that last night when I was testing my code and had in the ASP.NET textbox syntax type="number", I would get an "error" message on Submit (something like 'please enter a valid number'). This was using IE 10. Maybe if I add the 'step="0.01" I won't get this error.
>>Thank you very much for your input.
>
>Adding the step attribute should fix it - without it the validation only accepts whole numbers.....

You are very correct. The "step" solved the issue in IE. Strange though that the type='number' produces the correct control - spinner - in Chrome but not in IE. I guess IE is still catching up :).
Thank you.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform