diff --git a/f2/src/forms/LocationInfoForm.js b/f2/src/forms/LocationInfoForm.js index adb480283..0ce85149c 100644 --- a/f2/src/forms/LocationInfoForm.js +++ b/f2/src/forms/LocationInfoForm.js @@ -13,10 +13,12 @@ import { Link as ReactRouterLink } from 'react-router-dom' import { Flex, Icon } from '@chakra-ui/core' import { P } from '../components/paragraph' import { Button } from '../components/button' +import { Alert } from '../components/Messages' const defaultLocation = { postalCode: '', } +let postalValidation = true export const LocationInfoForm = props => { const [data, dispatch] = useStateValue() @@ -32,10 +34,27 @@ export const LocationInfoForm = props => { } } + function checkPostal(postal) { + var regex = new RegExp( + /^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ]( )?\d[ABCEGHJKLMNPRSTVWXYZ]\d$/i, + ) + if (regex.test(postal)) { + return true + } else { + return false + } + } + return (
{ + if (!checkPostal(values.postalCode) && values.postalCode !== '') { + postalValidation = false + } else { + props.onSubmit(values) + } + }} render={({ handleSubmit }) => ( @@ -83,6 +102,11 @@ export const LocationInfoForm = props => { )} + {postalValidation ? null : ( + + + + )} } button={} diff --git a/f2/src/locales/en.json b/f2/src/locales/en.json index 424a3ee7a..8c4f03b84 100644 --- a/f2/src/locales/en.json +++ b/f2/src/locales/en.json @@ -199,6 +199,7 @@ "landingPage.reportingOptions3": "If you encountered the incident online, you can also try reporting it to the website or app where it happened.", "landingPage.title": "Report a scam or computer crime", "landingPage.warning": "Reporting does not always lead to an investigation and we likely won’t be able to recover what was lost or damaged.", + "locationInfoForm.warning": "Please enter a valid postal code", "locationPage.intro": "We use your location to link your report to other reports in your area and to coordinate with local police services across Canada.", "locationPage.title": "Enter your location", "locationinfoPage.nextButton": "Continue", diff --git a/f2/src/locales/fr.json b/f2/src/locales/fr.json index 58464fa81..e2b6f8bd6 100644 --- a/f2/src/locales/fr.json +++ b/f2/src/locales/fr.json @@ -199,6 +199,7 @@ "landingPage.reportingOptions3": "Si l’incident s’est produit en ligne, vous pouvez le signaler sur le site Web ou sur l’application où il a eu lieu.", "landingPage.title": "Signalez une fraude ou un crime informatique", "landingPage.warning": "Les signalements ne mènent pas toujours à une enquête. Il est peu probable que nous puissions récupérer ce qui a été perdu ou endommagé.", + "locationInfoForm.warning": "Veuillez entrer un code postal valide", "locationPage.intro": "Nous utilisons votre emplacement géographique pour établir un lien entre votre rapport et les autres rapports de votre région, et pour collaborer avec les services de police locaux partout au Canada.", "locationPage.title": "Votre emplacement géographique", "locationinfoPage.nextButton": "Continuer",