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

Posted on 2009-12-28
Last Modified: 2013-12-13
I need a regex expression to validate a string that should have only numbers and of length 5.
Please help..
Question by:panshul007
    LVL 21

    Expert Comment

    [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
    LVL 21

    Accepted Solution

    /\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


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


    Author Closing Comment

    Thanks for the help..

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    In our personal lives, we have well-designed consumer apps to delight us and make even the most complex transactions simple. Many enterprise applications, however, are a bit behind the times. For an enterprise app to be successful in today's tech wo…
    The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
    The viewer will learn how to create multiple layers to apply various filters and how to delete areas from each layer’s filter.
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now