skip to Main Content

i have a from just simple form there is an input field for Linkedin url. Is there is anyway to validate that field only accepts linkedin url? Thanks

2

Answers


  1. Using JS you can check if the input value matches a pattern for a LinkedIn URL, Like this demo:

    $("#validateurl").click(function(){
      pattern = new RegExp(/(https?)?:?(//)?(([w]{3}||ww).)?linkedin.com(w+:{0,1}w*@)?(S+)(:([0-9])+)?(/|/([w#!:.?+=&%@!-/]))?/);
      if(!pattern.test($("#urlvalue").val())) {
        alert("Url not valid");
      } else {
        alert("Valid url");
      }
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <input type="text" id="urlvalue" />
    <button id="validateurl"> Validate </button>

    Examples of valid URLs:

    http://linkedin.com/in/jjjjjj
    
    https://www.linkedin.com/company/somecompany/
    

    Examples of not valid URLs:

    http://test.com
    
    http://www.aaa.com/444
    
    Login or Signup to reply.
  2. Using JS you can check if the input value matches a pattern for a LinkedIn URL.I hope solve your problem:

    $("#BtnCheck").click(function(){
      val = $('#UrlVal').val();
      if( /(ftp|http|https)://?(?:www.)?linkedin.com(w+:{0,1}w*@)?(S+)(:([0-9])+)?(/|/([w#!:.?+=&%@!-/]))?/.test(val) )
      {
       alert( 'valid Linkedin URL' );
      }
      else
      {
       alert( 'not valid Linkedin URL' );
      }
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <input type="text" id="UrlVal" />
    <button id="BtnCheck"> Check </button>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search