Skip to content

Instantly share code, notes, and snippets.

@jabis
Created April 13, 2016 18:51
Show Gist options
  • Save jabis/f4f6c5a4e62a2493fcfe19f1b110dc2a to your computer and use it in GitHub Desktop.
Save jabis/f4f6c5a4e62a2493fcfe19f1b110dc2a to your computer and use it in GitHub Desktop.
validator.js
var validator = module.exports = {
isDecimal : function(input) { return (/^(?=.)\d*(\.\d{1,9})?$/.test(input)); },
isNull : function(input) { return ((input == null) || (typeof input === "string" && input.replace(/\s/g, "") == "") || (typeof input === "undefined") || (input.length == 0)); },
isAlpha : function(input) { return (/^[a-zA-Z]+$/.test(input) && !validator.isNull(input)); },
isAlphanumeric : function(input) { return !(/\WöäåÖÄÅ/.test(input)); },
isNumeric : function(input) { return (/^-?(?:0$0(?=\d*\.)|[1-9]|0)\d*(\.\d+)?$/.test(input)); },
isEmail : function(input) { return (!validator.isNull() || (/^(?:[a-z0-9!#$%&'*+\/=?^_`{|}~-]\.?){0,63}[a-z0-9!#$%&'*+\/=?^_`{|}~-]@(?:(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\])$/i).test(input)); }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment