Created
January 5, 2016 23:42
-
-
Save seantomburke/79cc141fe336d04478ca to your computer and use it in GitHub Desktop.
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
const REGEX_PATTERNS = { | |
ip4: /((\d{1,3}\.){3}\d{1,3})/, | |
onlyDigits: /(^[\d\s]+$)/, | |
urlKeywords: /(https?(:\/\/)?|www\.)/i, | |
specialChars: /([!@#$%^&*+=|<>?:;\/\\])/, | |
emailAddress: /([\w\.-]+@\w+(\.\w+)+)/, | |
emailVerbose: /(.+?at(.+)?\w+?(.+)?(dot|\.)(.+)?com[^a-zA-Z]?)/i, | |
topLevelDomains: /(\.(com|edu|gov|int|mil|net|org|arpa)[^a-zA-Z]?)/i, | |
linkedinKeywords: /(linkedin|member|official)/i, | |
moreThanOneDigits: /(\d.*\d)/, | |
consecutiveAlphaNumeric: /((\w)\2{2,})/i, | |
secondaryLevelDomains: /(\w+\.\w+\.(ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|fi|fj|fk|fm|fo|fr|fx|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zr|zw|com|edu|gov|int|mil|net|org|arpa|nato)[^a-zA-Z]?)/i | |
}; | |
let nameValidations = [ | |
REGEX_PATTERNS.consecutiveAlphaNumeric.source, //must be first for lookaround | |
REGEX_PATTERNS.ip4.source, | |
REGEX_PATTERNS.onlyDigits.source, | |
REGEX_PATTERNS.urlKeywords.source, | |
REGEX_PATTERNS.specialChars.source, | |
REGEX_PATTERNS.emailAddress.source, | |
REGEX_PATTERNS.emailVerbose.source, | |
REGEX_PATTERNS.topLevelDomains.source, | |
REGEX_PATTERNS.linkedinKeywords.source, | |
REGEX_PATTERNS.moreThanOneDigits.source, | |
REGEX_PATTERNS.secondaryLevelDomains.source | |
].join('|'); | |
let headlineValidations = [ | |
REGEX_PATTERNS.urlKeywords.source, | |
REGEX_PATTERNS.ip4.source, | |
].join('|'); | |
let nameRegex = new RegExp(nameValidations); | |
let headlineRegex = new RegExp(headlineValidations); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment