By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,708 Members | 2,080 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,708 IT Pros & Developers. It's quick & easy.

Integer size

100+
P: 173
Hi,

what function can i use to ensure that a user can only enter a integer consisting of five digits and no more? Is there a function for this?

checked perldoc but couldnt find what im looking for..

regards
Feb 24 '09 #1
Share this Question
Share on Google+
3 Replies


KevinADC
Expert 2.5K+
P: 4,059
There is no function although there are probably modules that provide a function you could use to validate the user input. You can use a regexp:

Expand|Select|Wrap|Line Numbers
  1. unless ($var =~ /^\d{5}$/) {
  2.    print "No good, too many or too few digits\n";
  3. }
  4.  
Feb 24 '09 #2

100+
P: 173
thanks for this,

im not at the level at the moment to understand the example you have provided...

can you please explain this bit ($var =~ /^\d{5}$/)...

thanks
Feb 24 '09 #3

KevinADC
Expert 2.5K+
P: 4,059
$var is the string with the digits
=~ is the binding operator
/ is the beginning of regexp delimiter
^ is the beginning of string anchor
\d is a digit
{5} is a quantifier meaning exactly 5
$ is the end of string anchor
/ is the end of regexp delimiter

google for some perl regular expressions tutorials. Regular expressions can take a long time to learn, they are definetly one of the harder things to lean in any language that supports them. The one I posted though is very basic and using nothing I would consider advanced for a regexp.
Feb 24 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.