p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning HTML, XHTML, CSS, and JavaScript (http://p2p.wrox.com/forumdisplay.php?f=541)
-   -   Validate numeric and decimal data during keypress event (http://p2p.wrox.com/showthread.php?t=78914)

Hannibal April 8th, 2010 06:19 AM

Validate numeric and decimal data during keypress event

I am using classic ASP and Javascript

How to restrict the user to only enter integer or decimal values and cannot enter text in my TextBox field. The user should be able to type only one decimal point

For example: 3.45 is valid while 3.34. is invalid

I want to validate in javascript during the key press event in the textbox.

Please help.
Thank you

PeterPeiGuo April 8th, 2010 09:21 AM

Use regular expression, for example, /^[-+]?[0-9]*\.?[0-9]+$/. You may have to slightly adjust this to fit your specific needs. Your specific needs might be, for example: 1) Only accept numbers with two digits after decimal point; or 2) Accept 3. as a valid number and take it as 3.0.

Hannibal April 8th, 2010 10:24 AM

Is it possible to call the regular expression during the key press event

PeterPeiGuo April 8th, 2010 02:14 PM

Yes, try it out. If you run into issues, post your code and we can go from there.

All times are GMT -4. The time now is 08:37 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.