Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > HTML > BOOK: Beginning HTML, XHTML, CSS, and JavaScript
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning HTML, XHTML, CSS, and JavaScript
This is the forum to discuss the Wrox book Beginning HTML, XHTML, CSS, and JavaScript by Jon Duckett; ISBN: 978-0-470-54070-1
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning HTML, XHTML, CSS, and JavaScript section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 8th, 2010, 06:19 AM
Authorized User
 
Join Date: Feb 2006
Location: Bangalore, Karnataka, India.
Posts: 63
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Hannibal
Default Validate numeric and decimal data during keypress event

Hi,

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
Reply With Quote
  #2 (permalink)  
Old April 8th, 2010, 09:21 AM
Friend of Wrox
 
Join Date: Dec 2008
Location: , , .
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

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.

Last edited by PeterPeiGuo; April 8th, 2010 at 09:36 AM..
Reply With Quote
  #3 (permalink)  
Old April 8th, 2010, 10:24 AM
Authorized User
 
Join Date: Feb 2006
Location: Bangalore, Karnataka, India.
Posts: 63
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Hannibal
Default

Is it possible to call the regular expression during the key press event
Reply With Quote
  #4 (permalink)  
Old April 8th, 2010, 02:14 PM
Friend of Wrox
 
Join Date: Dec 2008
Location: , , .
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i assign keypress event on F2 kau_shuk VS.NET 2002/2003 1 August 25th, 2006 08:49 PM
keypress event kau_shuk VB.NET 2002/2003 Basics 1 July 31st, 2006 11:21 AM
how can use keypress event in a web application? agnihotrived .NET Framework 2.0 2 April 24th, 2005 09:14 PM
KeyPress event jbenson001 VB.NET 2002/2003 Basics 1 March 24th, 2005 04:52 PM
Keypress Event bharatsaboo VB.NET 2002/2003 Basics 0 February 25th, 2005 03:34 AM



All times are GMT -4. The time now is 08:52 PM.


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