1832870 Members
5103 Online
110048 Solutions
New Discussion

user input

 
Kris_5
Occasional Advisor

user input

Hi Folks,

What is the best to find out the given value/format is O.K. User will input the parameter mins=10,20,30 or mins=10-20 or mins=10 (all of them are acceptable.) and I need to findout that user has not entered garbage. I wrote a program using awk, so I need this check in awk program. Thanks in adv.

Kris
1 REPLY 1
Rodney Hills
Honored Contributor

Re: user input

Here is a sample piece of code. By using arrays in awk, you can parse and test the data.

mins="10,20,30"
ok=1
split(mins,ary,",")
for (xx in ary) {
split(ary[xx],c,"-")
for (yy in c) {
if (! match(c[yy],"^[0-9]+$")) { ok=0 }
}
}
print ok

The variable "ok" will be 0 if mins is not ok and 1 if mins is ok.

PS: Perl could do this a lot easier...


-- Rod Hills
There be dragons...