How to validate a LinkedIn public profile url

后端 未结 9 2682
迷失自我
迷失自我 2021-02-20 16:43

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 abl

相关标签:
9条回答
  • 2021-02-20 16:50

    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);
    };
    
    0 讨论(0)
  • 2021-02-20 16:50

    I've simply used the following regex:

    http(s)?:\/\/([w]{3}\.)?linkedin\.com\/in\/([a-zA-Z0-9-]{5,30})\/?
    

    According to the latest Linkedin documentation custom profile url can have 5-30 letters or numbers.

    It works for the following list of url:

    https://www.linkedin.com/in/your-profile-5-30-length/
    https://linkedin.com/in/your-profile-5-30-length/
    http://www.linkedin.com/in/your-profile-5-30-length/
    http://linkedin.com/in/your-profile-5-30-length/
    
    0 讨论(0)
  • 2021-02-20 16:51

    I've found a number of ways the profile url can look like:

    http://uk.linkedin.com/pub/some-name/1/1b3/b45/
    http://nl.linkedin.com/pub/other-name/11/223/544
    http://www.linkedin.com/in/aname/
    http://www.linkedin.com/in/another-name
    http://linkedin.com/in/name
    http://nl.linkedin.com/in/name
    http://nl.linkedin.com/in/name/
    

    I've used this regex to describe it:

    ^https?://((www|\w\w)\.)?linkedin.com/((in/[^/]+/?)|(pub/[^/]+/((\w|\d)+/?){3}))$
    

    It is not strict-strict but it got me home.

    edit
    - Added https support

    0 讨论(0)
  • 2021-02-20 16:58

    Following expression will help you with all patterns:

    ((https?:\/\/)?((www|\w\w)\.)?linkedin\.com\/)((([\w]{2,3})?)|([^\/]+\/(([\w|\d-&#?=])+\/?){1,}))$
    

    Demo

    https://regex101.com/r/oT7iM2/5

    0 讨论(0)
  • 2021-02-20 16:58

    This is tested regular expression that I use on my website. I fit all the variations that currently exist.

    var linkedin=/(https?)?:?(\/\/)?(([w]{3}||\w\w)\.)?linkedin.com(\w+:{0,1}\w*@)?(\S+)(:([0-9])+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
    
    0 讨论(0)
  • 2021-02-20 17:06

    There a very nice examples on the developer API pages http://developer.linkedin.com/

    This http://developer.linkedin.com/plugins/member-profile-plugin could be what your looking for.

    0 讨论(0)
提交回复
热议问题