Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Daterange Regex Help needed

Last post 05-19-2008, 1:38 AM by mash. 1 replies.
Sort Posts: Previous Next
  •  05-19-2008, 12:40 AM 42374

    Daterange Regex Help needed

    Hello Everyone.

    I am working on a .NET 3.5 project that needs a regex for date range.  I have tried using Expresso and have searched http://regexlib.com/ but have come up empty handed.

    the regex needs to be able to accept the following input (yyyy - yyyy) AND (yyyy) can can not accept years earlier than 1900 or later than 3000 (needs to cap somewhere)

    here are some examples of some valid entries
    1999 - 2000
    1980 - 1981
    2008

    here are some examples of invalid entries
    1800 - 1801
    asdf
    12345

    Thank you so much for the help.


    Chase

    Visual Studio 2008
    ASP.NET 3.5 (Visual Basic)
    Filed under: , , , ,
  •  05-19-2008, 1:38 AM 42378 in reply to 42374

    Re: Daterange Regex Help needed

    You do understand that a regex is not going be able to tell you if your values are ascending, right? http://regexadvice.com/blogs/mash/archive/2007/06/01/Are-you-ready-for-regex_3F00_.aspx

    You can check that both values are within a range but not that the first is less than the second.  You'd have to do that in your code. Also regexes to match ranges aren't always easy to adjust.

    \b(((19|2\d)\d\d)|3000)\b

    would find 4 digit values within range you asked for.

    \b(((19|2\d)\d\d)|3000)\b(\x20*-\x20*\b(((19|2\d)\d\d)|3000)\b)?

    matches your samples but also would match 1999-1990


    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
View as RSS news feed in XML