Update validation
This commit is contained in:
parent
061c923ff4
commit
1f4488c568
@ -15,14 +15,16 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
// Function to validate URLs
|
// Function to validate URLs
|
||||||
const isValidURL = (url) => {
|
const isValidURL = (url) => {
|
||||||
const pattern = new RegExp(
|
const pattern = new RegExp(
|
||||||
'^(https?:\\/\\/)?' + // Protocol (http or https)
|
'^(https?:\\/\\/)' + // Protocol (http or https)
|
||||||
'(([a-zA-Z0-9_-]+\\.)+[a-zA-Z]{2,6})' + // Domain name
|
'(([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,})' + // Domain name
|
||||||
'(\\/[a-zA-Z0-9@:%_\\+.~#?&//=]*)?$', // Path, query, or fragment
|
'(\\:[0-9]{1,5})?' + // Optional port number
|
||||||
|
'(\\/.*)?$', // Path, query string, or fragment
|
||||||
'i'
|
'i'
|
||||||
);
|
);
|
||||||
return pattern.test(url);
|
return pattern.test(url);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Function to add https:// if missing
|
// Function to add https:// if missing
|
||||||
const addHttpsIfMissing = (url) => {
|
const addHttpsIfMissing = (url) => {
|
||||||
if (!/^https?:\/\//i.test(url)) {
|
if (!/^https?:\/\//i.test(url)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user