Created
February 21, 2014 21:41
-
-
Save philipashlock/9144111 to your computer and use it in GitHub Desktop.
MIME regex test
This file contains hidden or 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
<html lang="en"> | |
<head> | |
<title>MIME regex</title> | |
</head> | |
<body> | |
<pre> | |
<script type="text/javascript"> | |
var regex = { | |
'MIME regex' : /^[-\w]+\/[-\w]+(\.[-\w]+)*([+][-\w]+)?$/ | |
} | |
var testMIMEs = { | |
'microsoft' : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", | |
'filename' : "file.doc", | |
'csv' : "text/csv" | |
} | |
for (var r in regex) { | |
document.write('\n Testing using ' + r +'\n'); | |
for (var d in testMIMEs) { | |
if (regex[r].test(testMIMEs[d])) { document.write('[valid]: '+testMIMEs[d]+'\n'); } | |
else { document.write('[invalid]: '+testMIMEs[d]+'\n'); } | |
} | |
document.write('\n'); | |
} | |
</script> | |
</pre> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment