Skip to content

Instantly share code, notes, and snippets.

@akirattii
Created March 7, 2019 05:18
Show Gist options
  • Save akirattii/3f91f3a77602c957dc1ead8fd626d851 to your computer and use it in GitHub Desktop.
Save akirattii/3f91f3a77602c957dc1ead8fd626d851 to your computer and use it in GitHub Desktop.
MEMO: Pure JS super simple basic type validation functions.
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