validate icon indicating copy to clipboard operation
validate copied to clipboard

Enhancement Request - Add IsActiveURL Validation Rule

Open sCuz12 opened this issue 2 years ago • 1 comments

Issue Summary:

I would like to request the addition of a new validation rule called "IsActiveURL" to the validation package. This rule will be used to validate whether a given URL is an active and accessible website.

Description: Currently, the validation package provides various rules for common validation tasks. However, there is a need for a specific rule to check if a URL is not only valid in format but also leads to an active website. This is especially useful for scenarios where we want to ensure that URLs provided by users actually lead to live webpages.

Expected Behavior: The IsActiveURL validation rule should make an HTTP request to the provided URL and confirm that the URL is reachable and returns a valid response (e.g., status code 200). If the URL is unreachable or returns an invalid response, the validation should fail

Use Case: Imagine a scenario where we have a form field for users to input their website URLs. We want to ensure that the URLs they provide are not only correctly formatted but also lead to active websites. This can be crucial for applications that rely on accurate and functioning URLs.

Example type User struct { Website string `validate:"isActiveURL"` }

sCuz12 avatar Jan 30 '24 07:01 sCuz12

@sCuz12 Maybe you should add a custom validator like isActiveURL

global add:

validate.AddValidator("isActiveURL", func(val string) bool {
	// ... check the URL: val
	// eg. http.Get(val)
	return true
})

inhere avatar Jan 30 '24 13:01 inhere