![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Validate Variables insert from user | DDoS | Shell Programming and Scripting | 8 | 04-08-2009 06:16 AM |
| How to Validate | SanjayLinux | Shell Programming and Scripting | 10 | 09-27-2007 07:16 AM |
| Validate if user and group exist | thedon | UNIX for Advanced & Expert Users | 2 | 03-21-2006 07:47 PM |
| validate input from user for file name | jerardfjay | Shell Programming and Scripting | 2 | 08-11-2005 11:53 AM |
| validate | ruffenator | Shell Programming and Scripting | 3 | 01-22-2002 10:37 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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"
Code:
# ./test.py 12323332 not ok # ./test.py 12345678901 ok # ./test.py "sdfs$%%^%&" not ok |
|
||||
|
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. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|