I am a newbie with Javascript and would like to check if a text
provided by a users , during filling in an input field , has digits
only.
Any idea?
Thank you
L 10 2706
PythonistL wrote:
I am a newbie with Javascript and would like to check if a text
provided by a users , during filling in an input field , has digits
only.
Any idea?
Thank you
L
Something like:
if (isNAN(document.getElementById('myTextField').valu e))
{
code if not number;
}
else
{
code if is number;
}
Jeff Paffett wrote on 15 sep 2006 in comp.lang.javascript :
PythonistL wrote:
>I am a newbie with Javascript and would like to check if a text provided by a users , during filling in an input field , has digits only. Any idea? Thank you L
Something like:
if (isNAN(document.getElementById('myTextField').valu e))
{
code if not number;
}
else
{
code if is number;
}
"Not a number"
is not the same as
"String has digits only"
Try:
if (/[^\d]/.test(document.getElementById('myTextField').value )) {
code if not number;
} else {
code if is number;
}
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Evertjan. wrote:
Jeff Paffett wrote on 15 sep 2006 in comp.lang.javascript:
PythonistL wrote:
I am a newbie with Javascript and would like to check if a text
provided by a users , during filling in an input field , has digits
only.
Any idea?
Thank you
L
Something like:
if (isNAN(document.getElementById('myTextField').valu e))
{
code if not number;
}
else
{
code if is number;
}
"Not a number"
is not the same as
"String has digits only"
Try:
if (/[^\d]/.test(document.getElementById('myTextField').value )) {
code if not number;
} else {
code if is number;
}
If you wanted to prevent anything but digits being accepted while
typing, you could attach a function to the onkeypress event of the
textfield and return false for non-digit keystrokes. This way they
wouldn't show up when typed.
There's an example of the opposite on w3schools.com. I don't know how
clean the code is, but it looks like this:
<script type="text/javascript">
function noNumbers(e)
{
var keynum
var keychar
var numcheck
if(window.event) // IE
{
keynum = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which
}
keychar = String.fromCharCode(keynum)
numcheck = /\d/
return numcheck.test(keychar)
}
</script>
<form>
Type some text (numbers not allowed):
<input type="text" onkeypress="return noNumbers(event)" />
</form>
Maybe some more seasoned developers could fix any bad coding.
>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Tom Cole wrote on 15 sep 2006 in comp.lang.javascript :
If you wanted to prevent anything but digits being accepted while
typing, you could attach a function to the onkeypress event of the
textfield and return false for non-digit keystrokes. This way they
wouldn't show up when typed.
I think that it is a bad idea, to have the field not reacting to certain
key presses. It distubs and alienates the user.
[And it was not the OQ]
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Evertjan. wrote:
Tom Cole wrote on 15 sep 2006 in comp.lang.javascript:
>If you wanted to prevent anything but digits being accepted while typing, you could attach a function to the onkeypress event of the textfield and return false for non-digit keystrokes. This way they wouldn't show up when typed.
I think that it is a bad idea, to have the field not reacting to certain
key presses. It distubs and alienates the user.
I would have to agree with you that having the browser
do flat out nothing as a response to a keystroke is very disturbing.
It probably would not be so bad , if *while* refusing
the keystroke , that the user received some feedback
like perhaps a <divappearing with a "numbers only please" hint
that went away when the user pressed a number.
JRS: In article <Xn********************@194.109.133.242>, dated Fri, 15
Sep 2006 13:33:47 remote, seen in news:comp.lang.javascript, Evertjan.
<ex**************@interxnl.netposted :
>"Not a number" is not the same as "String has digits only"
Pereant, inquit, qui ante nos nostra dixerunt.
>Try:
if (/[^\d]/.test(document.getElementById('myTextField').value )) {
code if not number; } else {
code if is number; }
\D == [^\d]
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/- FAQqish topics, acronyms & links;
Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Evertjan. wrote:
Tom Cole wrote on 15 sep 2006 in comp.lang.javascript:
If you wanted to prevent anything but digits being accepted while
typing, you could attach a function to the onkeypress event of the
textfield and return false for non-digit keystrokes. This way they
wouldn't show up when typed.
I think that it is a bad idea, to have the field not reacting to certain
key presses. It distubs and alienates the user.
It is also a very unreliable way to attempt to validate the field
content. - it is much better to look at the actual value of the field
as you suggested :-)
--
Rob
Dr John Stockton wrote on 16 sep 2006 in comp.lang.javascript :
JRS: In article <Xn********************@194.109.133.242>, dated Fri, 15
Sep 2006 13:33:47 remote, seen in news:comp.lang.javascript, Evertjan.
<ex**************@interxnl.netposted :
>>"Not a number" is not the same as "String has digits only"
Pereant, inquit, qui ante nos nostra dixerunt.
Dixit Aelius Donatus,
qui distingueri Tiberii Claudii Donati necesse est.
>>Try:
if (/[^\d]/.test(document.getElementById('myTextField').value )) { code if not number; } else { code if is number; }
\D == [^\d]
Certe!
\D === [^\d]
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
RobG wrote on 16 sep 2006 in comp.lang.javascript :
>
Evertjan. wrote:
>Tom Cole wrote on 15 sep 2006 in comp.lang.javascript:
If you wanted to prevent anything but digits being accepted while
typing, you could attach a function to the onkeypress event of the
textfield and return false for non-digit keystrokes. This way they
wouldn't show up when typed. I think that it is a bad idea, to have the field not reacting to certain key presses. It distubs and alienates the user.
It is also a very unreliable way to attempt to validate the field
content. - it is much better to look at the actual value of the field
as you suggested :-)
... which should be done, or at least repeated serverside.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Evertjan. wrote:
RobG wrote on 16 sep 2006 in comp.lang.javascript:
>Evertjan. wrote:
>>Tom Cole wrote on 15 sep 2006 in comp.lang.javascript:
If you wanted to prevent anything but digits being accepted while typing, you could attach a function to the onkeypress event of the textfield and return false for non-digit keystrokes. This way they wouldn't show up when typed.
I think that it is a bad idea, to have the field not reacting to certain key presses. It distubs and alienates the user.
It is also a very unreliable way to attempt to validate the field content. - it is much better to look at the actual value of the field as you suggested :-)
.. which should be done, or at least repeated serverside.
Actually checking from both the client side *and* the
server side is my preference. I know that I myself have
often enough groaned just as I hit a [ submit ] button,
realizing I would have to wait for another whole page load
just to fix a minor typo seen just a click too late. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: ratlhead |
last post by:
Hey all,
I've provided a form for a client of the company I work for that
basically emails the form data to an email address. Only a couple of
the many fields are required...nothing too fancy....
|
by: Steve Wylie |
last post by:
I am constructing an HTML questionnaire and one of the questions
requires people to rate some choices from 1 to 5, where 1 is their
favourite and 5 is their least favourite:
Car
Bus
Taxi cab...
|
by: Paul Telco |
last post by:
Hello,
I'm a new user designing a simple database to retrieve pre-prepared
docunents for printing.
I have five tables, a form to design the documents, a form to customise and
retrieve the...
|
by: Rey |
last post by:
Howdy all.
Appreciate your help with several problems I'm having:
I'm trying to determine if the Visit subform (subformVisits) has a new
record or been changed, i.e. dirty. The form that...
|
by: Chris Windsor |
last post by:
I hope the following describe what I'm trying to do:
I have created a tool to be used by product analysts when studying different
cell phone designs. Part of the tool is a set of 11 forms on a...
|
by: Jim M |
last post by:
To prevent data corruption I have replaced a memo field on my form with
an unbound control on my form that I populate with a function that
fills it from a memo field from my table. When the form is...
|
by: scprosportsman |
last post by:
Please help guys, i am trying to set up a database here at work and im
fairly new to access in terms of writing functions and queries and
stuff. I have 2 different places on my design that will...
|
by: starke1120 |
last post by:
Im creating a check in – check out database for RF guns. I have a
table that contains models.
ID (primary key)
Model
A table that contains Gun Details
ID (primary key)
Model_id...
|
by: Ben |
last post by:
Hi!
All of a sudden on a newer version of our application a check box on the
"Produce Invoice" form cannot be checked. I did not do any changes to this
form at all.
Below are the things that...
|
by: PhpCool |
last post by:
Hi, since sometime I'm stuck in a problem where I want to check or
uncheck all the checkboxes. If I'm choosing name for the checkbox
array as 'chkbx_ary' then I'm able to check/uncheck all the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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: 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: 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...
| |