Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to validate a LinkedIn public profile url

Tags:

php

linkedin

I am looking for a way to validate a link to make sure that it is pointing to a LinkedIn public profile page in PHP.

I have a website and I would like my users to be able to share their LinkedIn profile in their profile on my website.

like image 244
maaudet Avatar asked Dec 09 '11 19:12

maaudet


2 Answers

This covers most LinkedIn profile URLs (Javascript RegEx):

  • http://www.linkedin.com/in/username

  • https://www.linkedin.com/in/username

  • http://linkedin.com/in/username

  • https://linkedin.com/in/username

  • http://www.linkedin.com/mwlite/in/username

  • https://www.linkedin.com/mwlite/in/username

  • http://linkedin.com/mwlite/in/username

  • https://linkedin.com/mwlite/in/username

  • http://www.linkedin.com/m/in/username

  • https://www.linkedin.com/m/in/username

  • http://linkedin.com/m/in/username

  • https://linkedin.com/m/in/username

// Generic RegEx exact match validator
export const isRegexExactMatch = (value, regexp) => {
  const res = value.match(regexp);
  return res && res[0] && res[0] === res.input;
};

const isLinkedinProfileUrl = (value) => {
  const linkedInProfileURLRegExp =
    '(https?:\\/\\/(www.)?linkedin.com\\/(mwlite\\/|m\\/)?in\\/[a-zA-Z0-9_.-]+\\/?)';
  return !!isRegexExactMatch(value, linkedInProfileURLRegExp);
};
like image 74
Daniel Aviv Avatar answered Sep 27 '22 20:09

Daniel Aviv


I have this for all kind of URLs for Linkedin for javascript

export const isValidLinkedinUrl = (url) => {
  return /(https?:\/\/(www.)|(www.))?linkedin.com\/(mwlite\/|m\/)?in\/[a-zA-Z0-9_.-]+\/?/.test(url);
};

only RegExp

/(https?:\/\/(www.)|(www.))?linkedin.com\/(mwlite\/|m\/)?in\/[a-zA-Z0-9_.-]+\/?/
like image 37
AliRehman7141 Avatar answered Sep 27 '22 20:09

AliRehman7141