Created
March 7, 2019 05:18
-
-
Save akirattii/3f91f3a77602c957dc1ead8fd626d851 to your computer and use it in GitHub Desktop.
MEMO: Pure JS super simple basic type validation functions.
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
function isNumeric(s) { | |
return !isNaN(parseFloat(n)) && isFinite(n); | |
} | |
function isURL(s) { | |
return (/^https?\:\/\/(.+)/.test(s)); | |
} | |
function isJSON(s) { | |
let o; | |
try { | |
o = JSON.parse(s); | |
return true; | |
} catch (e) { | |
return false; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment