String validation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting String validation
# 1  
Old 10-07-2005
Validating a String

All

I want to validate a String. If it is "Deepak Xavier" then it will a valid string.
But if the value "Deepak #&xavier" then it should be invalid. Please give me some commands. Iam using KORN shell. Thanx in advance.


Regards
Deepak Xavier
# 2  
Old 10-07-2005
Code:
#! /bin/ksh

NAME="Deepak Xavier"

if [[ "$NAME" == "Deepak Xavier" ]] ; then
echo "User Name valid"
fi ;

Here is a link to the Oreilly's Learning the Korn Shell

I suggest you read through that.

vino
# 3  
Old 10-09-2005
String validation

All

I want to validate a String each character by character.And also it can allow space.This Script can allow only aplhabets and spaces. Please give me some commands or scripts. Iam using KORN shell.
Thanx in advance.

Regards
Deepak Xavier
# 4  
Old 10-09-2005
I have merged these two threads together because they are the same question.

Here is one way to verify that a string only has letters and spaces...
Code:
NAME="-Deepak #&xavier"
if [[ $NAME = $(echo "$NAME" | tr -dc '[A-za-z ]') ]]
then
   echo ok
else
   echo bad
fi


Last edited by Ygor; 10-10-2005 at 12:01 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Validation using While and IF

I am learning Shell scripting on own. I am trying to do an assignment to get details from the user like username their individual marks ,DOB and send a report in mail with the Details calculated like total and average. validate_marks() { local Value=$1 if && then return 0 else... (1 Reply)
Discussion started by: JayashreeRobin
1 Replies

2. Shell Programming and Scripting

Value validation

Hi All I am trying to validate a value using if condition requirement is need to check whether its a valid numeric value the input contains ( space, #N/A and negative and positive decimal values and Zeros) if it contains the space, I need to display the error message as space ... (15 Replies)
Discussion started by: tsurendra
15 Replies

3. Shell Programming and Scripting

Length validation

I am using below code to find the length of first column additionally I want the complete row which length is greater than 12.at the end I want the rows where first column data length is greater than 12. Just it should validate and highlight the rows where length(first column) is greater than... (5 Replies)
Discussion started by: srivalli
5 Replies

4. Shell Programming and Scripting

String validation in shell script

Hi All, I am a newbie...I would like to have a function which ll check if a file contains valid strings before "=" operator. Just to give you my requirement: assume my file has content: hello= gsdgsd sfdsg sgdsg sgdgdg world= gggg hhhh iiiii xxxx= pppp ppppp pppp my... (1 Reply)
Discussion started by: rtagarra
1 Replies

5. Shell Programming and Scripting

Name validation

Hi All, I need to write a small piece of code to check the following. name should contain (A-Z), spaces, hyphens & apostrophes I need to generate regular expressions for the same. Please help me out as i am not familiar with regular expressions. (1 Reply)
Discussion started by: lifzgud
1 Replies

6. Shell Programming and Scripting

Validation help

Hi, I am new to Unix shell scripting and need help to add some validation to an existing script. I've made a script that takes two argument (input) but I want the script to display an error message when nothing (null) is entered. So far I managed to validate the fist argument but fail to... (2 Replies)
Discussion started by: zen10
2 Replies

7. UNIX for Dummies Questions & Answers

Validation

I'm kinda new in shell scripting. How do i validate an input from a user to conform to requirement. For example, echo "Enter First Name: " read FName echo "Enter Date of Employment (dd/mm/yyyy): " read DoE If the user enters data that is alphanumeric, it accepts it. I hope i've... (1 Reply)
Discussion started by: Allenzo
1 Replies

8. UNIX for Dummies Questions & Answers

validation on a parameter

Hi guys! Im tryin to set up a login script that allows a user to login with only the following "forename.surname" . The username all contain lowercase letters so thats not a problem to sort out, but im having problems making sure that they can only enter 1 " . " . the code i have so far is this... (1 Reply)
Discussion started by: Henley55
1 Replies

9. Shell Programming and Scripting

String Validation program

Hi I want to validate the sting which one having only A-Z, a-z, *, . ,_ and 0-9 digits. Can anyone send me the program? I tried with following program but its taking all special characters like @ , # % and ^. echo " Enter Text :" read text while ') ] do echo "Character is wrong"... (4 Replies)
Discussion started by: mpk2006
4 Replies

10. Shell Programming and Scripting

string validation on a column

Hi there I have a file that I recieve that looks like the folowing, As these details are being manually entered by the customer, we sometimes get a few typos on 4th column (the 14 digit number starting with 42....) As you can see the first one has a space as the first character and then a 13 number... (3 Replies)
Discussion started by: hcclnoodles
3 Replies
Login or Register to Ask a Question