You need to sign in to do that
Don't have an account?

How to write Validation for URL ?
Hello Salesforce Experts,
Anyone please let me know how to write valition rule for URL ?
Else someone please provide regular expression string for URL ?
Thanks,
A small syntax change.
The following rule worked for me.
if(REGEX(URLfield__c,"^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$"),false,true)
Hope this helps.
Regards,
Satish Kumar
Please mark my answer as a solution if it was helpful so it is available to others as a proper solution.
If you felt I went above and beyond, please give me Kudos by clicking on the star icon.
All Answers
Following REGEX can be used for a website address.
^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$
Regards,
Satish Kumar
Please refer the below logic for validation rule, please let me know anything wrong,
if(REGEX("^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$",URLfield__c),false,true)
Thanks
A small syntax change.
The following rule worked for me.
if(REGEX(URLfield__c,"^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$"),false,true)
Hope this helps.
Regards,
Satish Kumar
Please mark my answer as a solution if it was helpful so it is available to others as a proper solution.
If you felt I went above and beyond, please give me Kudos by clicking on the star icon.
if(REGEX(URLfield__c,"^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$"),false,true)
Thanks
Yes.
But great....it works now...
Regards,
Satish Kumar
Please mark my answer as a solution if it was helpful so it is available to others as a proper solution.
If you felt I went above and beyond, please give me Kudos by clicking on the star icon.
Here is the result of using the following formula: if(REGEX("^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$",URLfield__c),false,true)
Some seemingly incorrect values are still accepted (e.g., http://www.gfh.") but most of it is okay.
This worked best for me, with trailing slashes, and things with query params and fragments. e.g. https://wwww.classpack.webnode.es/ciao/m?coa=cia&ci=boa#example What I find offputting is that the proposed solutions works perfectly in regex101 with Java flavor, but wouldn't work in Salesforce.
Another problem that's not supposed to be solved with regular expressions...
^(https?|ftp)://(-\.)?([^\s/?\.#-]+\.?)+([^\s]*)?$
This regular expression allows URLs starting with either "http", "https", or "ftp", and checks for valid domain names as the gbwa.download is for GB whatsapp (https://gbwa.download/) and any additional path or query parameters. Note that this regular expression is not foolproof and may not catch all variations of valid URLs.
In terms of writing a validation rule for a specific programming language, it will depend on the language you are using. In general, you can use the regular expression above and apply it to the input using the language's regular expression matching function. For example, in JavaScript:
const urlRegex = /^(https?|ftp)://(-\.)?([^\s/?\.#-]+\.?)+([^\s]*)?$/;
function validateUrl(url) {
return urlRegex.test(url);
}
In this example, validateUrl is a function that takes a string input url and returns a boolean indicating whether the input matches the URL regular expression.
^(https?|ftp)://[^\s/$.?#].[^\s]*$
This regular expression will match URLs that start with "http://", "https://", or "ftp://", followed by any characters that are not whitespace, "/", "?", "#", or ".". This will ensure that the URL is properly formed and does not contain any invalid characters.