add form validation

This commit is contained in:
2025-08-03 20:13:12 +02:00
parent 5ea702e7bb
commit 370507d5a6
+4 -1
View File
@@ -14,6 +14,9 @@ export default function Nominations() {
const [songURL, setSongURL] = useState(""); const [songURL, setSongURL] = useState("");
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const [message, setMessage] = useState(""); const [message, setMessage] = useState("");
const isSpotifyURL =
/^https:\/\/open\.spotify\.com\/track\/[a-zA-Z0-9]{22}/.test(songURL);
async function nominate(spotifyLink: string) { async function nominate(spotifyLink: string) {
try { try {
setIsAnimate(false); setIsAnimate(false);
@@ -54,7 +57,7 @@ export default function Nominations() {
<button <button
className="w-full rounded bg-blue-500 px-4 py-2 text-center font-bold text-white hover:bg-blue-400 disabled:cursor-not-allowed disabled:bg-gray-500" className="w-full rounded bg-blue-500 px-4 py-2 text-center font-bold text-white hover:bg-blue-400 disabled:cursor-not-allowed disabled:bg-gray-500"
type="submit" type="submit"
disabled={isLoading || !songURL.trim()} disabled={isLoading || !songURL.trim() || !isSpotifyURL}
onClick={async (e) => { onClick={async (e) => {
e.preventDefault(); e.preventDefault();
if (!songURL.trim()) return; if (!songURL.trim()) return;