Skip to content

Commit

Permalink
Add email format validation
Browse files Browse the repository at this point in the history
  • Loading branch information
carolinesalib committed May 20, 2020
1 parent e0d9674 commit 4a21551
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions app/javascript/containers/UserSettings/UserSettings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import changePictureImage from "../../images/user_settings_change_picture.svg";
import UserSettingsApi from "../../api/userSettingsApi";

// TODO: password min requirements validation
// TODO: phone validation
// TODO: phone validation/mask
// TODO: email validation

const NO_PASSWORD = 'NO_PASSWORD';
Expand Down Expand Up @@ -52,6 +52,9 @@ const UserSettings = (props) => {
const validateInput = (userSettings) => {
let errors = {};

// TODO: transform this into a new validation class
// ex: errors << Validation.requiredFields(userSettings, ['name', 'email', 'phone', 'password'])
// ex: errors << Validation.password(userSettings.password, userSettings.passwordConfirmation)
['name', 'email', 'phone', 'password'].map((inputName) => {
if (userSettings[inputName].trim() === '') {
errors[inputName] = {
Expand All @@ -60,7 +63,6 @@ const UserSettings = (props) => {
}
})


if (userSettings.password !== userSettings.passwordConfirmation) {
errors['password'] = {
message: null
Expand All @@ -71,6 +73,13 @@ const UserSettings = (props) => {
}
}

// TODO: do not override required validation
if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(userSettings.email))) {
errors['email'] = {
message: "E-mail inválido"
}
}

setFormErrors(errors)
}

Expand Down

0 comments on commit 4a21551

Please sign in to comment.