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 6629 acoder 16,027
Recognized Expert Moderator MVP
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
acoder 16,027
Recognized Expert Moderator MVP
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="ret urn numbersonly(thi s, event,true)"
hope usefull,
kind regards, maminx
gits 5,390
Recognized Expert Moderator Expert
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="ret urn numbersonly(thi s, 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
acoder 16,027
Recognized Expert Moderator MVP
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.
acoder 16,027
Recognized Expert Moderator MVP
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 not "", then
either the ref names has to be filled in OR the res date has to be
filled in. I have tried many combinations of this. Any suggestions...
|
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 (!isNumeric(document.frmA.f1.value)) {
alert("Please fill in Numeric")document.frmA.f1.value=""
document.frmA.f1.focus()
return false;
}
|
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 I
can have JS switch from one input field to another based on me
clicking in the empty box. Here is my code:
########## Start of code ...
|
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 to validate 3 types of fields: text, radio button, dropdown menu. but the code doesn't validate. After 2 days, it's time I asked for guidence....
| |
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.
Depends on the pull down list selection, I use script.aculo.us to validate the user input before submit and pass the necessary data, such as contact...
|
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 am working with is using .asp.
Their are 30 multiple choice questions. Each will have have 3 or 4 checkboxes where the test taker will choose only...
|
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 valid
input before inserting/updating? Test the length of a varchar/char field?
Validate an int field as valid numeric input (no alpha) ... and so...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
| |
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |