validate user ids


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting validate user ids
# 1  
Old 06-12-2009
validate user ids

Hi

I have to validate the user ids. It should be numeric. I am using following code
echo $input | grep '^[0-9]\{11\} > /dev/null
if [ $? = 1 ]
echo "error"
else
echo "Success"
fi
But when i entered user id as 828^&% the output is
[2] 8565
[3] 8566
-bash: ^: command not found
Means when i entered specila characters i am getting the above output. Can anyone help me out.

Thanx
# 2  
Old 06-12-2009
quote your $input variable.

alternatively, if you have Python,
Code:
#!/usr/bin/env python
import sys
userinput = sys.argv[1]
if userinput.isdigit() and len(userinput)==11:
    print "ok"
else:
    print "not ok"

output:
Code:
# ./test.py 12323332
not ok
# ./test.py 12345678901
ok
# ./test.py "sdfs$%%^%&"
not ok

# 3  
Old 06-12-2009
Code:
 
echo "0920920-902992" | awk '$0 ~/[^0-9-]/ {print "non numeric" }'


Last edited by panyam; 06-12-2009 at 06:42 AM..
# 4  
Old 06-12-2009
special character validation except '-'

here i have a concern forgot to mention that user allowed to entered user id range like

0920920-902992 (valid)
92920-9292%^& ( invalid)

so i need to do special character validation which allows '-' and numerics only.
# 5  
Old 06-12-2009
i changed the validation above a bit i think it is OK.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Create a bundle of user ids

if I want to create a bundle of user ids on some aix servers, if there is a way not need to do "passwd username" one by one user to set the password? Thanks (3 Replies)
Discussion started by: rainbow_bean
3 Replies

2. Shell Programming and Scripting

How to validate user's input..?

$Input_filename=$ARGV; if (!-d $Input_filename && ! -e $Input_filename) { print "USAGE: Please enter '$ABCD/def/dsed.txt' as an arguement \n"; exit; } 1. Input Is suppose to be something like "$ABCD/def/dsed.txt". if the input is wrong the script should throw an ERROR message.... (2 Replies)
Discussion started by: Rashid Khan
2 Replies

3. Shell Programming and Scripting

Is there a simpler way to validate user input for float?

I'm trying to only read price (FLOAT (i.e 1.10, 3.14, etc etc)) If the input is just an integer, I will add a .00 behind. (i.e 3 becomes 3.00 , 20 becomes 20.00) If the input is without 2 decimal places, I'll add a 0. (i.e 3.1 becomes 3.10) I tried using the below code, it works but I don't... (6 Replies)
Discussion started by: andylbh
6 Replies

4. UNIX for Dummies Questions & Answers

Scripting - process and user ids...Help please

Hello all: Working on a job I was asked get a simple script to perform the following task and would like to ask for some help. I'm looking forward to learning more and diving deeper into the World of Open Source servers. I need a script for a Unix server, using as few lines as possible, that... (4 Replies)
Discussion started by: moahten
4 Replies

5. UNIX for Dummies Questions & Answers

BASH validate user input

Hey, im trying to validate a user input and need some help. The input needs to be just a single letter. Im using a case to so this eg: read answer case $answer in *) echo "OK" ;; *) echo "This is a number" read answer ;; *) echo... (2 Replies)
Discussion started by: 602chrislys
2 Replies

6. Shell Programming and Scripting

Validate Variables insert from user

Hi Can you help me validate 2 variables?The first is an input date from the user and should be like this (yyyy-mm-dd). The second variable is an input time from the user and should be like this(hh:mm).When the input is wrong i want to give the chance to the user to insert again the date or time... (8 Replies)
Discussion started by: DDoS
8 Replies

7. UNIX for Advanced & Expert Users

Validate if user and group exist

I'm kinda new to unix programming so bear with me... I'm running a script prompting a user for an existing user and group and want to be able to validate if they valid. Is there any code available? Any help or push in the right direction would help. Thank you, (2 Replies)
Discussion started by: thedon
2 Replies

8. Shell Programming and Scripting

validate input from user for file name

Hello, This may have been addressed already somewhere, however I am looking for the easiest/shortest way to validate a response from a user for a file name. The file name should not have any of the following characters ~`!@#$%^&*()_-+={|\:;"'<,>.?/ Further the response should not have any... (2 Replies)
Discussion started by: jerardfjay
2 Replies

9. UNIX for Dummies Questions & Answers

Creating user ids on multiple systems simultaneously

I am trying to think of a way to create user ids on multiple Linux systems in one fell swoop without logging onto each system indivually. Is there a way to do this with ssh commands? I don't want to use NIS/LDAP solution just a simple shell script utilitarian methodoloy would suffice. Also, I am... (1 Reply)
Discussion started by: darthur
1 Replies
Login or Register to Ask a Question