function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Bhaswanthnaga vivek vutukuriBhaswanthnaga vivek vutukuri 

URL format validation

Hello, 

Can anyone please help me in validating URL format ?

I used the following Regular expression but it is working good, its showing even valid URL's as Invalid 

^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$ 

Grazitti TeamGrazitti Team
Hi,

Use the following regular expression to validate URL format: -
/^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/i

And don't forget to mark this answer as best, if answer this helps you :-)

--
Regards,
Grazitti Team
Web: http://www.grazitti.com


Bhaswanthnaga vivek vutukuriBhaswanthnaga vivek vutukuri
Hi grazitti team,
I am getting Syntax error when i used your regular expression :(
Grazitti TeamGrazitti Team
Hi,

Can you please try the "jquery validate" to valiadte the Url format?

Please see the below link and code for refrence:

http://jqueryvalidation.org/url-method


VisualForce Page:
<apex:form id="formId">
     <script type="text/javascript">
		jQuery('[id$=formId]').each(function(){
			jQuery(this).validate();
	    });
		jQuery('[id$=url]').rules("add",{
			url: true
		});
     </script>
	<apex:outputlabel for="url">UrlTovalidate</apex:outputlabel></span>
	<apex:inputText label="" value="test" id="url"/>
</apex:form>

Please mark as best answer if it solves your problem.

Regards,
Grazitti Team,
www.grazitti.com
Bhaswanthnaga vivek vutukuriBhaswanthnaga vivek vutukuri

Hey hi,
I need to write for some field in an Sobject ,
I tried in NOT(REGEX(url,^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$)) but no use...
Now I used IF() it is working now

thnks for reply