Regular Expressions 101

Community Patterns

A HREF validation

1

Regular Expression
ECMAScript (JavaScript)

/
<a\s.*href\s?=\s?["'](\bmailto:\b|\bhttp:\/\/\b|\bhttps:\/\/\b).*["'].*?>.*?<\/a>
/
gi

Description

Checks for well formed <a> tags. Must include mailto, http or https. Must have quoted href. Other attribues before or after href are accepted. Must be ended with </a>

Submitted by thedotfactor - 8 years ago