How to validate a LinkedIn public profile url

后端 未结 9 2893
迷失自我
迷失自我 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);
    };
    

提交回复
热议问题