473,320 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Validating form

51
Hi
i dont have much idea in javascript.i have a web application where i would like to validate a text field. user will only be able to insert floating number (like 4.5, 10.45). no letter will be allowed.

please assit.

Best regards
Mainul
Feb 8 '07 #1
9 1244
dmjpro
2,476 2GB
try thsi code in js
function validate()
{
// to access text value do ======= document.all.textfield_name.value
}
plz send me what u want to do
i am online
Feb 8 '07 #2
acoder
16,027 Expert Mod 8TB
If you know regular expressions, use the following for floating point number:
Expand|Select|Wrap|Line Numbers
  1. /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/
then test:
Expand|Select|Wrap|Line Numbers
  1. var reFloat = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/
  2. if (!reFloat.test(yourformfield)) alert("Error: not a floating point number")
Feb 8 '07 #3
acoder
16,027 Expert Mod 8TB
try thsi code in js
function validate()
{
// to access text value do ======= document.all.textfield_name.value
}
plz send me what u want to do
i am online
document.all is old code and IE-specific. You should use document.getElementById("textfieldid").value instead.
Feb 8 '07 #4
dmjpro
2,476 2GB
sorrryyyyyyyyyyyyyyy
without reading the problem i responded...
u can stop user to press alphabatic word...
try this code ....
<input type = text onkeypress = test()>

function test()
{
if(!(event.keyCode>=49&&event.keyCode<=57)) event.keyCode = 0;
if(event.keyCode == point_keycode && event.srcElement.value.indexOf('.') == -1) event.keyCode = 0;
}

to get the point_keycode try this code ...
<body onkeypress = test()>
function test()
{
alert(event.keyCode);
}

plz press any key u want to know it's keyCode..
plz maintain the case sensivity while u writing the code..
any problem while u write the code plz send me ur problem.....
i am online
Feb 8 '07 #5
mainul
51
thanks a lot guys for quick response. let me try the codes.

best regards
Mainul
Feb 8 '07 #6
dmjpro
2,476 2GB
ok try it quickly and send me ur result
i am eager to know the result
Feb 8 '07 #7
karthi84
271 100+
sorrryyyyyyyyyyyyyyy
without reading the problem i responded...
u can stop user to press alphabatic word...
try this code ....
<input type = text onkeypress = test()>

function test()
{
if(!(event.keyCode>=49&&event.keyCode<=57)) event.keyCode = 0;
if(event.keyCode == point_keycode && event.srcElement.value.indexOf('.') == -1) event.keyCode = 0;
}

to get the point_keycode try this code ...
<body onkeypress = test()>
function test()
{
alert(event.keyCode);
}

plz press any key u want to know it's keyCode..
plz maintain the case sensivity while u writing the code..
any problem while u write the code plz send me ur problem.....
i am online
hi dmjpro,
the coding is good. can u get me the key code for special keys like *,-,+ etc.
Feb 8 '07 #8
dmjpro
2,476 2GB
can't u get it from my code.....
Feb 8 '07 #9
acoder
16,027 Expert Mod 8TB
To get the event code across all browsers and not just IE, use
Expand|Select|Wrap|Line Numbers
  1. function setEvent(Id) {
  2.  Id.onkeypress = function keyPress(evt) { 
  3.   if (evt) 
  4.    keyCode = evt.keyCode ;
  5.   else  
  6.    keyCode = event.keyCode ;
  7.  alert(keyCode);
  8.  }
  9. }
http://www.bigbold.com/snippets/posts/show/309
Feb 8 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Bradley Bossard via DotNetMonster.com | last post by:
I am having an issue with the .NET framework (or C#) and validating events. I have implemented several validating event handlers for textboxes on a form. When I run the app, the form works...
2
by: Chris Dunaway | last post by:
I have a form with a textbox and numerous panels, buttons and other controls. I have handled the textbox Validating and Validated events. The textbox will hold a filename. In the validating...
0
by: Matthew | last post by:
All, I have searched google and the newsgroups but can't find anything the same as what I am experiencing (though I may have missed something). I have controls (textboxes) within UserControls...
0
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852...
21
by: Darin | last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. WHen the user clicks on...
4
by: easoftware | last post by:
I am using VS .Net 2003 and VB. I have an app with one parent and two Mdi child forms. I need to validate data in the Mdi form. The Form.Validating event works when I try to close a Mdi form,...
16
by: Al Santino | last post by:
Hi, It appears displaying a messagebox in a validating event will cancel the subsequent event. In the program below, button 2's click event doesn't fire if you open a dialog box in button 1's...
1
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
I've noticed that controls do not raise a Validating event if they are contained in a ToolStripDropDown via a ToolStripControlHost item. Please run the following sample and follow the instructions...
8
by: Peted | last post by:
I have an amazing problem which i think i have no hope of solving Im working with a c# dot net module that is hosted by and runs under a delphi form envrioment. Dont ask me how this insanity has...
2
by: Peted | last post by:
Hi if i derive a reference to a control on a winform (ie Control activeControl = somecontrol on the form) how can i test if that control has a validating or validated event and more importantly...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.