diff --git a/src/sections/Community/Web-based-from/index.js b/src/sections/Community/Web-based-from/index.js index dc186a7aa3f1..e2517b5ed2ba 100644 --- a/src/sections/Community/Web-based-from/index.js +++ b/src/sections/Community/Web-based-from/index.js @@ -7,6 +7,38 @@ import { Field, Formik, Form } from "formik"; import axios from "axios"; import { Link } from "gatsby"; +const validateEmail = (value) => { + let error; + + if (!value) { + error = "Required"; + } else if (!/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/.test(value)) { + error = "Please enter a valid email address"; + } + return error; +}; + +const validatePictureUrl = (value) => { + let error; + if (value) { + + if (value.startsWith("data:")) { + error = "Data URIs are not allowed. Please provide a URL, starting with http:// or https:// to an image file."; + } else { + try { + new URL(value); + const allowedImageExtensions = ["jpg", "jpeg", "png", "webp", "svg", "gif"]; + const extension = value.split(".").pop().toLowerCase(); + if (!allowedImageExtensions.includes(extension)) { + error = "URL must point to an image file (jpg, jpeg, png, svg, webp or gif)."; + } + } catch (_) { + error = "Please enter a URL to an image file."; + } + } + } + return error; +}; const WebBasedForm = () => { @@ -99,60 +131,63 @@ const WebBasedForm = () => { nextStep(); }} > -
- - e.target.setCustomValidity("Please fill-in this field")} onInput={e => e.target.setCustomValidity("")} /> - - e.target.setCustomValidity("Please fill-in this field")} onInput={e => e.target.setCustomValidity("")} /> - - e.target.setCustomValidity("Please fill-in this field")} onInput={e => e.target.setCustomValidity("")} /> - - - - - - - - - - - -
-
+ + + {errors.picture && touched.picture &&
{errors.picture}
} +

Please provide a link to your profile photo. Profile photos are used for community member profiles of longstanding community members.

+