hi gud mrng,
in my form....i need to take either single digit in textbox i.e., '1' or '12'..what i did is as follows
login.jsp -
<td><font color="#800000" size=""><b>Alert-Msg-Time (in Hrs)</b></font></td>
-
<td><input type="text" name="alertMsg" maxlength="6"></td>
-
<td></td>
-
login.js -
if (document.frm.alertMsg.value == "")
-
{
-
alert("Enter Alert Msg Time");
-
document.frm.alertMsg.focus();
-
return (false);
-
}
-
var chkAlrtmsg = /^[0123456789]{2}$/;
-
if (chkAlrtmsg.test(document.frm.alertMsg.value))
-
{}
-
else
-
{
-
alert('Invalid \" Alert Msg Time \" Entry');
-
return false;
-
}
-
here i used regExp for taking 2 digits...but i need is it should take either of them....can anyone help me out...
thanks,
madhu.
20 2975
why did you define a size (textbox) of 6, when you only need one of 2?
PS.
hi,
thanks..its working i removed the 'maxlength'...i had another problem with another label..called 'L-Units'....in this txtbox i need to enter 'decimal numbers' as well as it should not take letters nor -ve values...here is my code.
login.jsp -
<td></td>
-
<td><font color="#800000" size=""><b>L-Units</b> </font></td>
-
<td><input type="text" name="localUnits" id="localUnits"> </td>
-
<td></td>
-
login.js -
if (document.frm.localUnits.value == "")
-
{
-
alert("Enter Local Units");
-
document.frm.localUnits.focus();
-
return false;
-
}
-
var chklocalUnits = "0123456789";
-
var checklocalUnitsStr = document.frm.localUnits.value;
-
var alllocalUnitsValid = true;
-
for (i = 0; i < checklocalUnitsStr.length; i++)
-
{
-
ch = checklocalUnitsStr.charAt(i);
-
for (j = 0; j < chklocalUnits.length; j++)
-
if (ch == chklocalUnits.charAt(j))
-
break;
-
if (j == chklocalUnits.length)
-
{
-
alllocalUnitsValid = false;
-
break;
-
}
-
}
-
if (!alllocalUnitsValid)
-
{
-
alert("Enter only numeric in the \" Local Units \" field , No -ve's are allowed.");
-
document.frm.localUnits.focus();
-
return (false);
-
}
-
var localUnitsValid = document.getElementById('localUnits').value;
-
for(var i1 = 0; i1 < localUnitsValid.length; i1++)
-
{
-
currentCode = localUnitsValid.charCodeAt(i1);
-
if(currentCode!=45 && currentCode!=46 && currentCode<48 || currentCode>57)
-
{
-
alert('Only Numbers are allowed in Local Units Valid');
-
return false;
-
}
-
if(localUnitsValid.indexOf('.')!=-1 && localUnitsValid.lastIndexOf('.')!=localUnitsValid.indexOf('.')){
-
alert('A number can only have one decimal point');
-
return false;
-
}
-
}
-
wht i wrote in js it is not accepting 'Decimal numbers'...but it is accepting 'No -ve values to be entered and letters not to be entered'....can u suggest where i wnt wrong...
'-ve' means 'negative' value....
the txtbox should not take 'negative' values...whts wrng in my code...
IMO, too complicated test logic. convert the value into a number (parseFloat()) and test for NaN (not a numerical input) and x < 0.
i had deleted some part of js code...here the code is -
var stdUnitsValid = document.getElementById('stdUnits').value;
-
for(var i2 = 0; i2 < stdUnitsValid.length; i2++)
-
{
-
currentCode = stdUnitsValid.charCodeAt(i2);
-
if(currentCode!=45 && currentCode!=46 && currentCode<48 || currentCode>57)
-
{
-
alert('Only Numbers are allowed in Local Units Valid');
-
return false;
-
}
-
if(stdUnitsValid.indexOf('.')!=-1 && stdUnitsValid.lastIndexOf('.')!=stdUnitsValid.indexOf('.')){
-
alert('A number can only have one decimal point');
-
return false;
-
}
-
}
I am still of the opinion, that you think too complicated. convert the input in a number and test, whether it is negative.
i tried what u suggested...the problem im facing is if i enter the negative no. it is not showing any alert..i used if condition but not wrkng...hw to check for that..i removed if condition ..my code is -
if (document.frm.localUnits.value == "")
-
{
-
alert("Enter Local Units");
-
document.frm.localUnits.focus();
-
return false;
-
}
-
-
var localUnitsValid = document.getElementById('localUnits').value;
-
for(var i2 = 0; i2 < localUnitsValid.length; i2++)
-
{
-
currentCode = localUnitsValid.charCodeAt(i2);
-
if(currentCode!=45 && currentCode!=46 && currentCode<48 || currentCode>57)
-
{
-
alert('Only Numbers are allowed in STD Units Valid');
-
return false;
-
}
-
}
-
localUnitsValid = Math.abs(localUnitsValid);
-
document.getElementById('localUnits').value = Math.abs(localUnitsValid)
i tried what u suggested...
according to your posted code, you did not.
sorry for that i used 'Math' function...and i got it...by submitting the form..'negative' values converts to postive value in my o/p..but i need alert msg...where shld i code..
hi,
im getting alert msg...i came to knw where i kept wrng..here is my chngd code.. -
if (localUnitsValid != Math.abs(localUnitsValid))
-
{
-
alert('entered -ve value');
-
localUnitsValid = Math.abs(localUnitsValid);
-
return false;
-
}
what about if (localUnitsValid < 0) ?
im entering the values in txtbox...if the txt box is left empty..i'll throw an alert...
that means...i coded as follows. -
if (document.frm.localUnits.value <=0)
-
{
-
alert("Enter Local Units");
-
document.frm.localUnits.focus();
-
return false;
-
}
not a good idea. if you have non-numerical input (aka letters) how does that compare to 0?
k then suggest me how to do...
I already did that in post #7.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: sinister |
last post by:
The examples in the online manual all seem to use double quotes, e.g. at
http://us3.php.net/preg_replace
Why? (The behavior is different with single quotes, and presumably simpler
to...
|
by: Joshua Beall |
last post by:
Hi All,
I have heard other people say that PHP can parse double quoted strings
(e.g., "Hello, World") faster than it can parse single quoted strings (e.g.,
'Hello, World'). This seems backwards...
|
by: Dynamo |
last post by:
Hi,
I am still confused as when to use single or double quotes.
This works:
echo "<td>" . $row . "</td>";
and this does not
|
by: Sybren Stuvel |
last post by:
Hi there!
I'm a beginning Python programmer, and I like it a lot already. Since my
Sharp Zaurus has a fairly complete Python environment including PyQT, I
thought it would be the perfect...
|
by: Diarmaid McGleenan |
last post by:
Hi all. This isn't quite the same single/double-quote problem we see
posted a multitude of times in this ng. Read on...
I have a js function called ShowActiveLink which accepts a string...
|
by: Sakharam Phapale |
last post by:
Hi All,
How to capture Mouse Single click and mouse double click event on Commnad
Button.
I am doing as follows.
Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As...
|
by: Tor Aadnevik |
last post by:
Hi,
I have a problem converting values from Single to double.
eg. When the Single value 12.19 is converted to double, the result is
12.1899995803833.
Anyone know how to avoid this?
Regards...
|
by: R.Biloti |
last post by:
Hi folks
I wrote the naive program to show up the unit roundoff (machine
precision) for single and double precision:
#include <stdio.h>
int main (void)
{
double x;
|
by: bill |
last post by:
I am trying to write clean code but keep having trouble deciding
when to quote an array index and when not to.
sometimes when I quote an array index inside of double quotes I
get an error about...
|
by: eaocomp |
last post by:
How do I trigger a single or double-click events when a user clicks a column within the gridview. I want the event to trigger and open a pop-up page related to the selected column.
There are no...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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: 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...
|
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,...
| |