Skip to content

Instantly share code, notes, and snippets.

@lancejpollard
Created March 20, 2013 05:12
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lancejpollard/5202460 to your computer and use it in GitHub Desktop.
Save lancejpollard/5202460 to your computer and use it in GitHub Desktop.
common javascript data/values
/**
* Email matcher.
*/
exports.emailRegex = /^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!\.)){0,61}[a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61}[a-zA-Z0-9]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/;
exports.urlRegex = /^(?!mailto:)(?:(?:https?|ftp):\/\/)?(?:\S+(?::\S*)?@)?(?:(?:(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))|localhost)(?::\d{2,5})?(?:\/[^\s]*)?$/i;
exports.urlMaxLength = 2083;
exports.ipRegex = /^(?:(?: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]?)$/;
// US
exports.zipcodeRegex = /^\d{5}(-\d{4})?$/;
// UK
exports.postcodeUKRegex = /[A-Z]{1,2}[0-9]{1,2} ?[0-9][A-Z]{2}/i;
exports.alphaRegex = /^[a-zA-Z]+$/;
exports.alphanumericRegex = /^[a-zA-Z0-9]+$/;
exports.numericRegex = /^-?[0-9]+$/;
exports.hexRegex = /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
exports.rgbRegex;
exports.hslRegex;
exports.cssColorRegex;
exports.lowercaseRegex = /^[a-z0-9]+$/;
exports.intRegex = /^(?:-?(?:0|[1-9][0-9]*))$/;
exports.decimalRegex = /^(?:-?(?:0|[1-9][0-9]*))?(?:\.[0-9]*)?$/;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment