+ Start a Discussion
Naresh Krishna.ax1176Naresh Krishna.ax1176 

Website url validation in salesforce

Hi All,

 

I need to validate the website url which user entered in the apex page.

On salesforce docs, I found Website Extension validation rule (in it only checks for few extensions)

And also it is only to check extension.

 

Is there any procedure to validate website url in salesforce ?

 

Can anyone please help me with this.

 

Thanks.

Navatar_DbSupNavatar_DbSup

Hi,

 

Try the below code snippet as reference:

 

<apex:page >

<script>

 

function chkurl()

{

      var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/

      var urlvalue=document.getElementById('j_id0:j_id2:geturl').value;

      if(regexp.test(urlvalue))

      {

      }

      else

      {

      alert('enter a valid url');

      return false

      }

      return true;

}

</script>

<apex:form >

<apex:inputtext id="geturl"/>

<apex:commandButton value="test url" onclick="return chkurl()"/>

</apex:form>

</apex:page>

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.