|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Avoid common pitfalls of incorporating spreadsheets into Java apps. Read about it in the free white paper: “Five Biggest Blunders when Building Spreadsheet Applications in Java” Download Now! |
|
#1
|
|||
|
|||
|
Validating integer input
Hi,
Can anyone tell me how can I validate an input as Integer not character or anything else??? Is there any way to read the input without the user hitting the <Enter> key?? I really appreciate your help. Thanx ![]() |
|
#2
|
|||
|
|||
|
This will do
Code:
#!/bin/sh
getkey 2>/dev/null 1>/dev/null
KEY=`echo $?`
case $KEY in
48)
echo "0";;
49)
echo "1";;
50)
echo "2";;
51)
echo "3";;
52)
echo "4";;
53)
echo "5";;
54)
echo "6";;
55)
echo "7";;
56)
echo "8";;
57)
echo "9";;
esac
|
|
#3
|
|||
|
|||
|
What is getkey? It's definitely not part of the Bourne shell.
|
|
#4
|
|||
|
|||
|
I tried your code but doesn't seem to work though. The KEY variable is always set to 0. I put a sleep so it can wait for the user to input. Don't know whether thats the problem. Can you please help me mate.
#!/bin/sh while [ true ]; do sleep 2 getkey 2>/dev/null 1>/dev/null KEY=`echo $?` echo $? case $KEY in 48) echo "0";; 49) echo "1";; 50) echo "2";; 51) echo "3";; 52) echo "4";; 53) echo "5";; 54) echo "6";; 55) echo "7";; 56) echo "8";; 57) echo "9";; esac done Thanx.. |
|
#5
|
|||
|
|||
|
Sorry I missed a function there.
Code:
function getkey()
{
read -rsn 1 REPLY;
return $REPLY;
}
Also change the numbers from 48 - 57
as
0-9
Coded it in C mood :-)
Last edited by murugesan : July 8th, 2004 at 11:15 PM. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Validating integer input |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|