Check input for lenght, special characters and letter case


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check input for lenght, special characters and letter case
# 1  
Old 03-31-2011
CPU & Memory Check input for lenght, special characters and letter case

I made menu script for users so they can run other script without going in shell just from menu.

But i must control their input.
These are criteria:

Input must have 4 signs
First two signs are always lower case letters
Input shall not have some special signs just letters and numbers


example:
bz11
bzA1
ztSS
we4S


Code:
#! /bin/ksh
#

menu () {
  clear

  echo "                                                         "
  echo "                Test script                              "
  echo "                                                         "

}

nofile () {
sudo -u root /app/first/test/$choice.sh
}

file () {
read filename?"   Please input filename: "
sudo -u root /app/first/test/$choice.sh $filename
}

menu
choice=0
while test "x $choice" = "x 0"
do
  read choice?"Chose one : "
      case $choice in
    bz11) file
    ;;
    bz12) file
    ;;
      E) exit
    ;;
    *) nfile
  ;;

  esac
choice=0
done

# 2  
Old 03-31-2011
Try like..
Code:
case $choice in
        [a-z][a-z][A-Z0-9][A-Z0-9]) file
        ;;
        E) exit
        ;;
        *) nfile
        ;;
esac

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to delimit the fields of a input file which has special characters?

Hi All, I am a newbie to Shell scripting. I have a requirement to Delimit the file fields of a Input file having special characters and spaces with ";". Input File ---------------------------------- Server Port ---------------------------------- Local ... (5 Replies)
Discussion started by: Suganbabu
5 Replies

2. Shell Programming and Scripting

Change first letter of a word from lower case to upper case

Hi all, I am trying to find a way to change first letter in a word from lower case to upper case. It should be done for each first word in text or in paragraph, and also for each word after punctuation like . ; : ! ?I found the following command sed -i 's/\s*./\U&\E/g' $@ filenamebut... (7 Replies)
Discussion started by: georgi58
7 Replies

3. Shell Programming and Scripting

Upper case letter match

Hi, im able to search for string in a file (ex: grep -w "$a" input.txt). but i have to search for the uppercase of a string in a file where upper case of the file content matches something like below. where upper("$a")== converted to upper case string in (input.txt) can someone please provide... (5 Replies)
Discussion started by: p_satyambabu
5 Replies

4. Shell Programming and Scripting

Need HELP with AWK split. Need to check for "special characters" in string before splitting the file

Hi Experts. I'm stuck with the below AWK code where i'm trying to move the records containing any special characters in the last field to a bad file. awk -F, '{if ($NF ~ /^|^/) print >"goodfile";else print >"badfile"}' filename sample data 1,abc,def,1234,A * 2,bed,dec,342,* A ... (6 Replies)
Discussion started by: shell_boy23
6 Replies

5. Shell Programming and Scripting

Ommiting special characters as input - Help

Hey Everyone, I'm quite new to unix (hence the 0 posts!) and im trying to write a simple program that outputs what the user types in to the screen, as long as it is a letter. This part works fine, however, when a "\" is entered doesnt not display anything and moves to the next line. Is... (11 Replies)
Discussion started by: ultiron
11 Replies

6. Shell Programming and Scripting

Help in preserving special characters from input file

Hi Forum. I've tried to search online for a solution but I cannot seem to find one. Hopefully, someone here can help me out. I would appreciate it. Input file abc.txt: $InputFile_Borrower=CMTSLST\EDW_COMMERCIAL_MTGE_BORROWER_dat.lst... (14 Replies)
Discussion started by: pchang
14 Replies

7. Shell Programming and Scripting

Bourne Shell: Special characters Input Prevention

Environment: Sun UNIX Language: Bourne Shell Problem: I am writing a script that allows user to key in a directory. Example: /root/tmp. Since the user can key in anything he/she wants, I need to validate to make sure that he/she does not key in anything funny i.e.... (37 Replies)
Discussion started by: totziens
37 Replies

8. UNIX for Dummies Questions & Answers

How to add a space after an Upper case letter

Hi I have two questions. 1. how to convert "EverythingIsFine" to "Everything Is Fine" in a txt file. 2. how to convert everything to upper case letter and reverse, I hope there is a general purpose script for this. (1 Reply)
Discussion started by: onthetopo
1 Replies

9. Shell Programming and Scripting

Check for special characters in a script

Hi All, In my shell script, i'm checking the date input against few constraints. It should be of YYYYMMDD format and the script should prompt the user with error message, if less than 8 digits are present or input contains special characters (*,&,%,^,$ ...etc). The script i'm using is given... (7 Replies)
Discussion started by: sumesh.abraham
7 Replies

10. Shell Programming and Scripting

Covert case of first letter only

Using sed or tr, how do I change "fred" into "Fred" or "fReD" into "Fred" (1 Reply)
Discussion started by: tisons
1 Replies
Login or Register to Ask a Question