Telephone Format and Check


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Telephone Format and Check
# 1  
Old 04-26-2017
Telephone Format and Check

How can I script to check telephone number entered by user in a uniz script:

Code:
print -n "Enter telephone number to check ? " ; read telno

How do I script to :
1) Check if entered without dashes or with dashes
2) If without dashes how can I check:
if telno is only 10 digits, if so convert it to ###-###-#####
3) IF already has dashes and contains 10 digits, then continue?

Thank you
# 2  
Old 04-26-2017
Had you mentioned your shell, you'd received a taylored proposal. Here's one for bash:
1) [ ${telno} == ${telno#*-} ] && ... (required dash count not specified in post#1)
2) [ ${telno} == ${telno#*[^0-9]} ] && [ ${#telno} -eq 10 ] && echo ${telno:0:3}-${telno:3:3}-${telno:6}
3) Place in the "else" branches of above tests.
# 3  
Old 04-26-2017
Did not work. Updated code below

Code:
#!/bin/bash
read -p "Enter Telephone number to check: " telno
TnDash=`echo ${telno:0:3}-${telno:4:3}-${telno:8}`
if  [ ${telno} == ${telno#*[^0-9]} ] && [ ${#telno} -eq 10 ]; then
  TN=`echo ${telno:0:3}-${telno:3:3}-${telno:6}`
else
if [ ${telno} == ${TnDash} ]; then
  TN=$telno
else
  echo "Invalid number <$telno> entered. Entry must be numeric and 10 digits separated by dashes"
fi
fi
 PORTEDIN_NUM=$TN
echo "TN Entered = $PORTEDIN_NUM"

Here is the updated code. It seems to work fine. But is it a good way to check input telephone numbers and convert?

Output test #1 :

Code:
Enter Telephone number to check: 214-800-3000
Temp = 214-800-3000
TN Entered = 214-800-3000
Check current log for this TN?[y/n]

Output test #2:

Code:
Enter Telephone number to check: 214-800-3000
TN Entered = 214-800-3000


Last edited by mrn6430; 04-26-2017 at 09:33 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check Date Format And Email Out

Hello All, I have a requirement where i need to get the EXTRACT_DATE from a file and check if the date is of valid format or not and then mail it if it is not valid. Appreciate if you can help me with this. I did the following so far. awk '{for(i=1;i++<=NF;)if($i~/^EXTRACT_DATE/) print $i}'... (11 Replies)
Discussion started by: Ariean
11 Replies

2. Homework & Coursework Questions

Telephone book script

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Hi, here is my other assignment for the week. Create a shell script for a telephone book application. ... (7 Replies)
Discussion started by: Jagst3r21
7 Replies

3. Shell Programming and Scripting

Check input date format?

how to check input date format. for example $input_date must be in format dd.mm.gg script is execute like this: bin/script1.sh 14.12.2009 script1.sh code: #!/bin/sh input_date=$1 CMD="/app/si/test/test.sh $input_date" echo "*****" $CMD (2 Replies)
Discussion started by: waso
2 Replies

4. UNIX for Dummies Questions & Answers

File format check

How to check if file is in a given format? For instance: if file records are delimeted with "|" ( pipes) and have exactly 26 fields? File is pretty big (~3 mil reccords), so not sure if I have to check all records or just head/tail records or smth. Any ideas are much much more than... (11 Replies)
Discussion started by: Leo_NN
11 Replies

5. Shell Programming and Scripting

Check the format of Date

Hi, I have a date field in my input file. I just want to check if its in the format "DD-MM-YYYY". Is there any command which can achieve this? Thanks and Regards, Abhishek (2 Replies)
Discussion started by: AAA
2 Replies

6. UNIX for Dummies Questions & Answers

Got connected with Modem but cannot dial Telephone no. to connect to host

Hello There, I configure my Modem as follow. Step1. # admintool & Then from Browse --> Serial Port i select tta port and Edit --> Modify From that i select Template : Modem:Dial Out Baud Rate: 9600 Ok Step 2 # tip /dev/cua/a connected (1 Reply)
Discussion started by: abidmalik
1 Replies

7. IP Networking

all about telephone in unix

hai to all, that i came to know all telephone exchanges use unix.i want to know wheather we can connect telephones uaeing unix,if it possible means how&and also i need about more information about "telephones in unix" ... (1 Reply)
Discussion started by: radheesh
1 Replies

8. UNIX for Dummies Questions & Answers

telephone working in unix

sir, i came to know that telephone exchanges use unix for the working of telephones,that is when we take our hand set in telephone we can note a dial sound,for this telephone exchanges use unix. we are going to do project using unix,i want to know wheater we can able to connect... (1 Reply)
Discussion started by: radheesh
1 Replies
Login or Register to Ask a Question