Back to all resources
Regular Expressions
Input Validation
LinkedIn
jQuery

Validation for LinkedIn URLs

By Jared Malan
This JavaScript code defines a function validLinkedIn that checks if a given URL is a valid LinkedIn profile URL. The function uses a regular expression to match the URL format of LinkedIn profiles. The code also includes a jQuery event handler that triggers when an HTML element with the #linkedin-el loses focus (on "blur"). 

The regular expression in validLinkedIn function:

  • Allows optional "http://" or "https://".
  • Optionally allows "www.".
  • Checks for "linkedin.com/" followed by optional "mwlite/" or "m/" indicating mobile versions.
  • Ensures the URL path starts with "in/" followed by a LinkedIn username, which can include alphanumeric characters, underscores, hyphens, and periods.
  • Allows an optional trailing slash at the end of the URL.