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.
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);
};
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_.-]+\/?/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With