I try to validate inpute field for weight that accept only numeric value like 65.12 not allow any special character or character but allow '.' .
thanks
jha
8 6621
What have you attempted so far?
What have you attempted so far?
i am using this code for validation but this way only can check null,(-)value,and character with special caracter. but don't know how can do with my requirement like 45.10 - function ck_wt(obj)
-
{
-
if(obj.value=="")
-
{
-
obj.focus();
-
alert("Wt. Must be entered.")
-
}
-
else if(obj.value<0 || obj.value=="")
-
{
-
obj.focus();
-
alert("wait must be +ve")
-
return;
-
}
-
else if(!obj.value.match(/^\d+$/)){
-
obj.focus();
-
alert("Only numbers are allowed.");
-
return;
-
}
-
}
thanks
jha
Either use parseFloat and isNaN or use a simple float regular expression, e.g. /^\d{2}\.\d{2}$/
Either use parseFloat and isNaN or use a simple float regular expression, e.g. /^\d{2}\.\d{2}$/
the code for check wait is modified by but not work it accepted special character like 4.5a or 4.5;aq but i wants to 4.5 only or 4 - function ck_wt(obj)
-
{
-
if(obj.value=="")
-
{
-
obj.focus();
-
alert("Wt. Must be entered.")
-
}
-
else if(obj.value<0 || obj.value=="")
-
{
-
obj.focus();
-
alert("wait must be +ve")
-
}
-
else if(obj.value.match(/^\d{2}\.\d{2}$/))
-
{
-
obj.focus();
-
alert ("testing")
-
return;
-
}
-
}
jha
the code for check wait is modified by but not work it accepted special character like 4.5a or 4.5;aq but i wants to 4.5 only or 4 - function ck_wt(obj)
-
{
-
if(obj.value=="")
-
{
-
obj.focus();
-
alert("Wt. Must be entered.")
-
}
-
else if(obj.value<0 || obj.value=="")
-
{
-
obj.focus();
-
alert("wait must be +ve")
-
}
-
else if(obj.value.match(/^\d{2}\.\d{2}$/))
-
{
-
obj.focus();
-
alert ("testing")
-
return;
-
}
-
}
jha
i'm using this library below, u can use this - function numbersonly(myfield, e, dec) {
-
var key;
-
var keychar;
-
-
if (window.event)
-
key = window.event.keyCode;
-
else if (e)
-
key = e.which;
-
else
-
return true;
-
keychar = String.fromCharCode(key);
-
-
// control keys
-
if ((key==null) || (key==0) || (key==8) ||
-
(key==9) || (key==13) || (key==27) )
-
return true;
-
-
// numbers
-
else if ((("-0123456789").indexOf(keychar) > -1))
-
//else if ((("0123456789")))
-
return true;
-
-
// decimal point jump
-
else if (dec && (keychar == "."))
-
{
-
myfield.form.elements[dec].focus();
-
return false;
-
}
-
else
-
return false;
-
}
and to call that function in HTML form is with this event below :
onkeypress="return numbersonly(this, event,true)"
hope usefull,
kind regards, maminx
gits 5,390
Expert Mod 4TB
i'm using this library below, u can use this - function numbersonly(myfield, e, dec) {
-
var key;
-
var keychar;
-
-
if (window.event)
-
key = window.event.keyCode;
-
else if (e)
-
key = e.which;
-
else
-
return true;
-
keychar = String.fromCharCode(key);
-
-
// control keys
-
if ((key==null) || (key==0) || (key==8) ||
-
(key==9) || (key==13) || (key==27) )
-
return true;
-
-
// numbers
-
else if ((("-0123456789").indexOf(keychar) > -1))
-
//else if ((("0123456789")))
-
return true;
-
-
// decimal point jump
-
else if (dec && (keychar == "."))
-
{
-
myfield.form.elements[dec].focus();
-
return false;
-
}
-
else
-
return false;
-
}
and to call that function in HTML form is with this event below :
onkeypress="return numbersonly(this, event,true)"
hope usefull,
kind regards, maminx
@maminx: according to the posting guidelines USE THE CODE TAGS ... i'm getting tyred fixing every single post by you with that ...
regards,
MOD
the code for check wait is modified by but not work it accepted special character like 4.5a or 4.5;aq but i wants to 4.5 only or 4
Oh, I see you want any type of float number. What I suggested earlier was a very simple version from what you posted, but it seems you need something a little more complete. This link should help.
i'm using this library below, u can use this
...
It allows multiple "." decimal characters.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Hernán Castelo |
last post by:
hi
should i validate cookies values?
thanks
--
atte,
Hernán Castelo
SGA - UTN - FRBA
|
by: Meredith |
last post by:
I am using a script to validate a form using the presence of a value in
one field and determine if there is a value in one of two fields. It
is an either/or situation. If the date rcvd field is...
|
by: juicy |
last post by:
I done a numeric field checking as below, but I found that if I insert
float number (10.01), it validate it as non numeric and return false..
What is going wrong?
if...
|
by: Cranky |
last post by:
Ok, here is my scenario: I need to input numbers using my handheld
IPAQ. I figured out how to create an online numeric keypad for
inputting numbers into an input field, what I need to know is how...
|
by: TokyoJ |
last post by:
I run a small camp in Alaska for kids and my director is asking for a web form. Could someone please have a look and offer some advice on where I'm making mistake(s)?
I'm using the RegExp function...
|
by: SkipNRun |
last post by:
I am a novice when comes to JavaScript, AJAX. I am working on a form, which will allow users to update their contact information. In order to make the form flexible, I need to use pull down list.
...
|
by: mbarnhizer |
last post by:
Hello All,
Trying to figure out how to validate a series of questions on an online test. I am thinking that VB or Javascript is the best route, but your input may make a difference. The site i...
|
by: =?Utf-8?B?YyMganVua2ll?= |
last post by:
Title says it ... my C# web application uses a number of FormViews that are
inserted/updated/deleted via stored procedures.
Is there a way thru C# coding (example?) to validate a date field as...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |