HighDots Forums  

Solo numeri in campo di testo

Javascript (Italian) Il linguaggio JavaScript (it.comp.lang.javascript)


Discuss Solo numeri in campo di testo in the Javascript (Italian) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ugo
 
Posts: n/a

Default Solo numeri in campo di testo - 10-13-2006 , 06:35 AM






Ciao a tutti,

in una applicazione web vorrei fare in modo che in un campo di testo si
possano inserire solo numeri [0-9]

function check_num( obj )
{
if( isNaN( obj.value ) )
obj.value = obj.defaultValue;
else
obj.defaultValue = obj.value;
}

<input type="text" value="0" onkeyup="check_num(this)"
onchange="check_num(this)" ondrop="return false"
oncontextmenu="return false" onpaste="return false" />


Quante controindicazioni vedete?
C'e' qualche altro modo?

Reply With Quote
  #2  
Old   
Cristiano Larghi
 
Posts: n/a

Default Re: Solo numeri in campo di testo - 10-13-2006 , 06:45 AM






In data Fri, 13 Oct 2006 12:35:36 +0200, Ugo ha scritto:

Quote:
in una applicazione web vorrei fare in modo che in un campo di testo si
possano inserire solo numeri [0-9]
ok, quindi solo numeri interi

Quote:
function check_num( obj )
{
if( isNaN( obj.value ) )
isNaN restituirà false su un numero tipo 10.5, e non è quindi ciò che vuoi.
Funzionerà un qualcosa del tipo
if(obj.value.match(/\D/)

p.s. prenderà per buono un numero tipo 000000009 (ma è quello che hai
chiesto...è ciò che vuoi?)

Quote:
input type="text" value="0" onkeyup="check_num(this)"
onchange="check_num(this)" ondrop="return false"
oncontextmenu="return false" onpaste="return false" /
se hai verificato che questi eventi siano standard (mai avuta occasione di
testare/studiare i vari ondrop-onpaste-oncontextmenu) allora ok.

--
"That until there is no longer first class
And second class citizens of any nation
Until the colour of a man's skin
Is of no more significance than the colour of his eyes
Me say war"

B.M.


Reply With Quote
  #3  
Old   
Ugo
 
Posts: n/a

Default Re: Solo numeri in campo di testo - 10-13-2006 , 07:00 AM



Quote:
in una applicazione web vorrei fare in modo che in un campo di testo si
possano inserire solo numeri [0-9]
ok, quindi solo numeri interi
esatto

Quote:
function check_num( obj )
{
if( isNaN( obj.value ) )
isNaN restituirà false su un numero tipo 10.5, e non è quindi ciò che vuoi.
Ahh, ecco!

Quote:
Funzionerà un qualcosa del tipo
if(obj.value.match(/\D/)
ok, bene grazie.

Quote:
p.s. prenderà per buono un numero tipo 000000009 (ma è quello che hai
chiesto...è ciò che vuoi?)
si', tutto sommato, puo' andare bene...

Quote:
input type="text" value="0" onkeyup="check_num(this)"
onchange="check_num(this)" ondrop="return false"
oncontextmenu="return false" onpaste="return false" /
se hai verificato che questi eventi siano standard (mai avuta occasione di
testare/studiare i vari ondrop-onpaste-oncontextmenu) allora ok.
non sono standard, pero'...


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.