473,395 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Integer size

173 100+
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
3 3402
KevinADC
4,059 Expert 2GB
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
Beany
173 100+
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
4,059 Expert 2GB
$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

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

Similar topics

3
by: Shawn Berg | last post by:
Is the Integer data type deprecated? I am not sure what Integer data type to use in some of my classes. According to the URL below, if I am reading it correctly, it seems as though I should be...
8
by: Lash Rambo | last post by:
How does one go about programming in C++ without making assumptions about the size of types? Is it really possible? For instance, even the well-intentioned, portable C++ (and C) code I've seen...
45
by: Trevor Best | last post by:
I did a test once using a looping variable, first dimmed as Integer, then as Long. I found the Integer was quicker at looping. I knew this to be true back in the 16 bit days where the CPU's (80286)...
20
by: GS | last post by:
The stdint.h header definition mentions five integer categories, 1) exact width, eg., int32_t 2) at least as wide as, eg., int_least32_t 3) as fast as possible but at least as wide as, eg.,...
61
by: John Baker | last post by:
When declaring an integer, you can specify the size by using int16, int32, or int64, with plain integer being int32. Is integer the accepted default in the programming community? If so, is...
1
by: charles_gero | last post by:
Hi all, I had a question about the topics in the subject and posted to comp.std.c, but feel it may also be appropriate here. Please excuse this crosspost if it is in bad form. I have a...
21
by: no1zson | last post by:
I do not even know how to correctly ask this question. I have an item field in the code I am about to post. Simple intger meant to be an item number for a cd. The user enters this number. Over the...
17
by: Ivan K. | last post by:
I am looking at some legacy code, which begins by allocating a double matrix with the dmatrix() function from NRC as follows: double **A, **augin, **augout, **aa; A = dmatrix(1,...
130
by: euler70 | last post by:
char and unsigned char have specific purposes: char is useful for representing characters of the basic execution character set and unsigned char is useful for representing the values of individual...
5
by: kj | last post by:
I'm trying to subclass file, overriding the readline method. The new method definition begins with def readline(self, size=None): line = self.file.readline(size) # etc., etc. ....where the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.