validation: set field size to 6 digits


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting validation: set field size to 6 digits
# 1  
Old 08-30-2006
validation: set field size to 6 digits

I'm curious, how would I set validation on a field size to make sure it only ever accepts a 6 digit number?

I currently have validation for it to be an integer in place but can't find anywhere that says how to make it only a length of 6 digits.

any tips on the function I should be focussing on?
# 2  
Old 08-30-2006
Try:
Code:
INPUT=$1
if [ ${#INPUT} -ne 6 ]
then
   echo "ERROR: NUMBERS MUST BE 6"
   exit 2
fi
if [ $(echo ${INPUT}|grep -c "[0-9]\{${#INPUT}\}") -eq 0 ]
then
   echo "ERROR: ONLY NUMBERS PLEASE :-)."
   exit 2
fi

In adition u can use
Code:
typeset -Z6 INPUT

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Problem with getting awk to multiply a field by a value set based on condition of another field

Hi, So awk is driving me crazy on this one. I have searched everywhere and read man, docs and every related post Google can find and still no luck. The actual files I need to run this on are sensitive in nature, but it is the same thing as if I needed to calculate weighted grades for multiple... (15 Replies)
Discussion started by: cotilloe
15 Replies

2. UNIX for Beginners Questions & Answers

sed / awk script to delete the two digits from first 3 digits

Hi All , I am having an input file as stated below 5728 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r03_q_reg_20_/Q 011 611 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 011 3486... (4 Replies)
Discussion started by: kshitij
4 Replies

3. Shell Programming and Scripting

Splitting single row into multiple rows based on for every 10 digits of last field of the row

Hi ALL, We have requirement in a file, i have multiple rows. Example below: Input file rows 01,1,102319,0,0,70,26,U,1,331,000000113200000011920000001212 01,1,102319,0,1,80,20,U,1,241,00000059420000006021 I need my output file should be as mentioned below. Last field should split for... (4 Replies)
Discussion started by: kotra
4 Replies

4. Shell Programming and Scripting

Search for a value and replace other field in the same set

Hello friends, I have huge file with many sets where each "set" has few lines and each set always begins with "Set" in Sq brackets as shown above. # cat file1 (2 Replies)
Discussion started by: magnus29
2 Replies

5. Shell Programming and Scripting

Regex find first 5-7 occurrences of a set of digits within a string

Using these strings as an example: <a onclick="doShowCHys=1;ShowWindowN(0,'/daman/man.php?asv4=145148&amp;playTogether=True',960,540,943437);return false;" title=""> <a onclick="doShowCHys=1;ShowWindowN(0,'/daman/man.php?asv4=1451486&amp;playTogether=True',960,540,94343);return false;" title=""> <a... (12 Replies)
Discussion started by: metallica1973
12 Replies

6. Shell Programming and Scripting

Validation of Text field while Click on submit button

I am using Perl CGI. I have created some text fields and getting those values. But i want if user leave the text field blank when he click on submit button then instead of run a script it should give a popup. Please any body suggest me something..??? (0 Replies)
Discussion started by: Navrattan Bansa
0 Replies

7. Shell Programming and Scripting

Find filenames with three digits and add zeros to make five digits

Hello all! I've looked all over the internet and this site and have come up a loss with an easy way to make a bash script to do what I want to do. I have a file with a naming convention as follows: 2012-01-18 string of words here 123.jpg 2012-01-18 string of words here 1234.jpg 2012-01-18... (2 Replies)
Discussion started by: Buzzman25
2 Replies

8. Shell Programming and Scripting

Field size finder

hi i have a file and its contents is as below: 8290804808 1338108313 1313141441 13131313133 1313131311 33424242242 23242424242 i want to print only those fields in bold. how to do it? (3 Replies)
Discussion started by: pravfraz
3 Replies

9. Shell Programming and Scripting

How to set Field Separator for TCLSH??? :S

Hi, I am having a problem, with setting the FS in TCLSH, maybe someone knows the answer. I have a Tclsh/Tk script, and i“m trying to get all (only) the running processes for the given user like this: foreach process { puts stdout $process; } This also works, but... (2 Replies)
Discussion started by: laptop87
2 Replies

10. UNIX for Dummies Questions & Answers

set font size

can any one tell me how to set the font size in unix? (14 Replies)
Discussion started by: sachin.gangadha
14 Replies
Login or Register to Ask a Question