The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-12-2009
KiranKumarKarre KiranKumarKarre is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 62
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 (permalink)  
Old 06-12-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,533
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 (permalink)  
Old 06-12-2009
panyam panyam is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Posts: 474
Code:
 
echo "0920920-902992" | awk '$0 ~/[^0-9-]/ {print "non numeric" }'

Last edited by panyam; 06-12-2009 at 05:42 AM..
  #4 (permalink)  
Old 06-12-2009
KiranKumarKarre KiranKumarKarre is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 62
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 (permalink)  
Old 06-12-2009
panyam panyam is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Posts: 474
i changed the validation above a bit i think it is OK.
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:53 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0