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
Write a shell program to find the sum of alternate digits in a given 5-digit number banta Shell Programming and Scripting 4 10-30-2006 01:59 AM
Validate Failure of SFTP in PERL rahulrathod Shell Programming and Scripting 5 09-23-2005 08:37 PM
validate number range sabina Shell Programming and Scripting 5 02-23-2005 10:26 AM
restrain the number of digits of a PID mlefebvr UNIX for Advanced & Expert Users 1 05-27-2002 09:33 AM
a simple perl gusla UNIX for Dummies Questions & Answers 3 04-17-2002 02:01 AM

Closed Thread
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 09-10-2008
BufferExploder BufferExploder is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 9
PERL: Simple reg expr validate 6 digits number

Hi there!

I'm trying to validate a simple 6 digits number with reg expr. I ONLY want 6 digits so when i type 7 digits the script should no validate the number.

I've write this code:

#!/usr/bin/perl

while(<STDIN>){
if($_=~/\d{6}/){
print "Bingo!\n";
}else{
print "Error\n";
}
}


So when a type "123456" it validates well, when i type "1234567" ou "12345678" it validates too.

Many thanks !
  #2 (permalink)  
Old 09-10-2008
Ikon's Avatar
Ikon Ikon is offline Forum Advisor  
Registered User
  
 

Join Date: Jul 2008
Location: Phoenix, Arizona
Posts: 669
Code:
#!/usr/bin/perl

while(<STDIN>){
if($_=~/^\d{6}$/){
print "Bingo!\n";
}else{
print "Error\n";
}
}
  #3 (permalink)  
Old 09-10-2008
BufferExploder BufferExploder is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 9
Thank you very much Ikon for this solution!
Closed Thread

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 02:11 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