Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Regex Validation in Java to validate a String having numbers of length 5

Posted on 2009-12-28
3
Medium Priority
?
318 Views
Last Modified: 2013-12-13
Hello,
I need a regex expression to validate a string that should have only numbers and of length 5.
Please help..
0
Comment
Question by:panshul007
  • 2
3 Comments
 
LVL 21

Expert Comment

by:silemone
ID: 26132238
[0-9]{0,5} for up to 5 characters but can be less

[0-9][0-9][0-9][0-9][0-9]  simple 5 characters
0
 
LVL 21

Accepted Solution

by:
silemone earned 80 total points
ID: 26132267
/\d{5}/  for 5 digits   11111 will match but 1, 11, 111, 1111,  will not nor anything > 5

[0-9]{5] for five digits  save as the above

remember

[0-9]{0,5}  <-- this can be nothing, 1, 11, 111, 1111, 11111, but not > than 5

0
 

Author Closing Comment

by:panshul007
ID: 31670450
Thanks for the help..
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here in this article, you will get a step by step guidance on how to restore an Exchange database to a recovery database. Get a brief on Recovery Database and how it can be used to restore Exchange database in this section!
There can be many situations demanding the conversion of Outlook OST files to PST format and as such, there is no shortage of automated tools to perform this conversion. However, what makes Stellar OST to PST converter stand above the rest? Let us e…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Suggested Courses
Course of the Month20 days, 19 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question