Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 442827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:06:37+00:00 2026-05-12T21:06:37+00:00

Is there any way I can easily check if a string conforms to the

  • 0

Is there any way I can easily check if a string conforms to the SortableDateTimePattern (“s”), or do I need to write a regular expression?

I’ve got a form where users can input a copyright date (as a string), and these are the allowed formats:

Year: YYYY (eg 1997)

Year and month: YYYY-MM (eg 1997-07)

Complete date: YYYY-MM-DD (eg 1997-07-16)

Complete date plus hours and minutes: YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)

Complete date plus hours, minutes and seconds: YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)

Complete date plus hours, minutes, seconds and a decimal fraction of a second
YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)

I don’t have much experience of writing regular expressions so if there’s an easier way of doing it I’d be very grateful!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T21:06:38+00:00Added an answer on May 12, 2026 at 9:06 pm

    Not thoroughly tested and hence not foolproof, but the following seems to work:

    var regex:RegExp = /(?<=\s|^)\d{4}(-\d{2}(-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d{2})?)?\+\d{2}:\d{2})?)?)?(?=\s|$)/g;
    var test:String = "23 1997 1998-07 1995-07s 1937-04-16 " + 
                      "1970-0716 1993-07-16T19:20+01:01 1979-07-16T19:20+0100 " + 
                      "2997-07-16T19:20:30+01:08 3997-07-16T19:20:30.45+01:00";
    var result:Object
    while(result = regex.exec(test))
        trace(result[0]);
    

    Traced output:

    1997
    1998-07
    1937-04-16
    1993-07-16T19:20+01:01
    2997-07-16T19:20:30+01:08
    3997-07-16T19:20:30.45+01:00

    I am using ActionScript here, but the regex should work in most flavors. When implementing it in your language, note that the first and last / are delimiters and the last g stands for global.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way I can specify a standard or custom numeric format string
Is there any way where I can check if the field is numeric in
Is there any way I can detect when my page has been set as
Is there any way we can convert text to speech in an iPhone app?
Is there any way I can vary caching by a controller action parameter using
Is there any way i can access the page object from within the global.asax
If I create an application on my Mac, is there any way I can
Is there any way that I can programmatically create (and I guess access) hidden
Is there any way that I can change how a Literal of a code
Is there any way that I can find the container pointed to by an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.