Skip to content

Commit 2982c60

Browse files
committed
Refine URL regex for improved clarity and flexibility in validation
1 parent 9b4af5e commit 2982c60

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

frontend/src/utils/misc.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ export const validateEmail = (email) => {
1616
return re.test(String(email).toLowerCase());
1717
};
1818

19-
// More flexible URL regex that accepts:
19+
// Simple and flexible URL regex that accepts:
2020
// - URLs with or without protocol (http/https)
2121
// - URLs starting with www.
22-
// - Domain names without protocol or www (e.g., example.com)
23-
// - LinkedIn URLs with special characters
22+
// - Simple domain names like example.com
23+
// - LinkedIn URLs and other social media profiles
2424
export const urlRegex =
25-
/^(?:(?:(?:https?|ftp):)?\/\/)?(?:www\.)?(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|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;
25+
/^(https?:\/\/)?(www\.)?[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+([/?#][^\s]*)?$/i;
2626

2727
export const validateUrl = (value) => {
2828
return urlRegex.test(value);

0 commit comments

Comments
 (0)