Loic
08-31-2007, 02:01 AM
Hi, I am fairly new to JavaScript. and I am trying to find a script to validate a field for a survey. More specifically check if a field only has numbers. I found this script on the net, but there is one part of it that I don’t understand…
function checknumber() {
var x=document.checknum.pnum.value
var anum=/(^\d+$)|(^\d+\.\d+$)/
if (anum.test(x))
testresult=true
else{
alert("Please input a valid number!")
testresult=false
}
return (testresult)
}
</script>
<script>
function checkban() {
if (document.layers||document.all||document.getElementById)
return checknumber()
else
return true
}
</script>
What I don’t understand is what this specific part is doing well more how it works… I was wondering if someone could shead some light on my little problem here.. thanks :)
var anum=/(^\d+$)|(^\d+\.\d+$)/
function checknumber() {
var x=document.checknum.pnum.value
var anum=/(^\d+$)|(^\d+\.\d+$)/
if (anum.test(x))
testresult=true
else{
alert("Please input a valid number!")
testresult=false
}
return (testresult)
}
</script>
<script>
function checkban() {
if (document.layers||document.all||document.getElementById)
return checknumber()
else
return true
}
</script>
What I don’t understand is what this specific part is doing well more how it works… I was wondering if someone could shead some light on my little problem here.. thanks :)
var anum=/(^\d+$)|(^\d+\.\d+$)/