Skip to content

Instantly share code, notes, and snippets.

@philipashlock
Created February 21, 2014 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philipashlock/9144111 to your computer and use it in GitHub Desktop.
Save philipashlock/9144111 to your computer and use it in GitHub Desktop.
MIME regex test
<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