Created
June 8, 2015 23:08
-
-
Save gobengo/da762911509730fc2ba1 to your computer and use it in GitHub Desktop.
JavaScript xsd:dateTime Parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// built from definition: http://books.xmlschemata.org/relaxng/ch19-77049.html | |
var xsdDateTimePattern = new RegExp([ | |
'(\\d{4})', //year | |
'-', | |
'(\\d{2})', // month | |
'-', | |
'(\\d{2})', // day | |
'T', | |
'(\\d{2})', // hour | |
':', | |
'(\\d{2})', // minutes | |
':', | |
'(\\d{2}(\\.\\d+)?)', // seconds incl optional decimal fraction | |
'(Z|[+-](\\d{2}):(\\d{2}))' // time zone | |
].join('')) | |
/** | |
* Return whether the provided string is a valid xsd:dateTime | |
*/ | |
function isValidXsdDateTime(dateTimeStr) { | |
var match = dateTimeStr.match(xsdDateTimePattern); | |
return match; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment