Created
January 20, 2015 05:53
-
-
Save justsml/8623758d0b34cdb6994c to your computer and use it in GitHub Desktop.
Handy RegEx Validation Snippit
This file contains hidden or 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
/* | |
Credit and Source: https://www.owasp.org/index.php/OWASP_Validation_Regex_Repository | |
*/ | |
'use strict'; | |
module.exports = { | |
url: /^((((https?|ftps?|gopher|telnet|nntp):\/\/)|(mailto:|news:))(%[0-9A-Fa-f]{2}|[-()_.!~*';\/?:@&=+$,A-Za-z0-9])+)([).!';\/?:,][[:blank:]])?$/, | |
ip: /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/, | |
email: /^[a-zA-Z0-9+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/, | |
safeText: /^[a-zA-Z0-9 .-]+$/, | |
date: /^(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/, | |
creditCard: /^((4\d{3})|(5[1-5]\d{2})|(6011)|(7\d{3}))-?\d{4}-?\d{4}-?\d{4}|3[4,7]\d{13}$/, | |
password: /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,8}$/, | |
complexPassword: /^(?:(?=.*\d)(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[^A-Za-z0-9])(?=.*[a-z])|(?=.*[^A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[A-Z])(?=.*[^A-Za-z0-9]))(?!.*(.)\1{2,})[A-Za-z0-9!~<>,;:_=?*+#."&§%°()\|\[\]\-\$\^\@\/]{8,32}$/, | |
zipCode: /^\d{5}(-\d{4})?$/, | |
phone: /^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$/, | |
ssn: /^\d{3}-\d{2}-\d{4}$/, | |
filename: { | |
windows: /^(?!^(PRN|AUX|CLOCK\$|NUL|CON|COM\d|LPT\d|\..*)(\..+)?$)[^\x00-\x1f\\?*:\";|\/]+$/, | |
linux: /^(([a-zA-Z]:|\\)\\)?(((\.)|(\.\.)|([^\\\/:*?"|<>. ](([^\\\/:*?"|<>. ])|([^\\\/:*?"|<>]*[^\\\/:*?"|<>. ]))?))\\)*[^\\\/:*?"|<>. ](([^\\\/:*?"|<>. ])|([^\\\/:*?"|<>]*[^\\\/:*?"|<>. ]))?$/ | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment