Question

I have searched for a while and can't seem to find anything that's related to this.

I need to validate an ISO 8601 time interval. There is loads of stuff about ISO 8601 date times but i specifically need interval. I am using a regex and this is what I have so far;

Regex regEx = new Regex(@"^P((\d+)Y)((\d+)M)((\d+)D)(T)((\d+)H)((\d+)M)((\d+((.)?(\d)?(\d)?))S)$");

So basically this checks if the input string is fully formed eg P0Y0M1DT1H2M2.01S would be validated but the standard states that smaller strings such as PT4S should be accepted too.

If anyone can help me with this I would be much appreciated. I've been reading up on conditional regex but not too sure how to work it.

Many thanks.

Was it helpful?

Solution

After all i did find the answer as part of a Scorm related question.

link is here if anyone manages to stumble across my post first;

SCORM 2004 Time Format - Regular Expression?

OTHER TIPS

I have created a regular expression to get informations about interval in ISO 8601. Check it out:

^(P((?<Years>\d+)Y)?((?<Months>\d+)M)?((?<Days>\d+)D)?)(T((?<Hours>\d+)H)?((?<Minutes>\d+)M)?((?<Seconds>\d+((.)?(\d)?(\d)?))S)?)$
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top