Archives For regex

Regex Password Validation

I needed to find a regex pattern for validating a password for an Angular app.
The requirement were to have at least 1 lowercase character, 1 uppercase character, 1 number, and no repeating character more than 2. For the ng-pattern, I came up with is below

/^(?!.*([A-Za-z0-9])\1{2})(?=.*[a-z])(?=.*[A-Z])(?=.*\d).+$/

Breaking It Down

(?!.*([A-Za-z0-9])\1{2}) Make sure that no characters repeat more than twice

(?=.*[a-z]) requires at least one lowercase

(?=.*[A-Z]) requires at least one uppercase

(?=.*\d) requires at least one digit

function linkify(text) {
    var exp = /(\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’])))/ig;
    var linkedText = text.replace(exp,'<a href="$1" target="_blank">$1</a>');
    // when user puts in 'www' replace it with 'http://www'
    return linkedText.replace('="www.','="http://www.');
}

Sources:
StackOverflow
John Grubber’s RegEx for URL