Skip to content

Commit 4c1ebdf

Browse files
plxitycatarak
authored andcommitted
Email Validation added (#1120)
* changes * changes * changes * changes * changes
1 parent 7fdd970 commit 4c1ebdf

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

client/modules/User/components/ResetPasswordForm.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function ResetPasswordForm(props) {
1717
id="email"
1818
{...domOnlyProps(email)}
1919
/>
20+
{email.touched && email.error && <span className="form-error">{email.error}</span>}
2021
</p>
2122
<input
2223
type="submit"

client/modules/User/pages/ResetPasswordView.jsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
import PropTypes from 'prop-types';
23
import React from 'react';
34
import { Link, browserHistory } from 'react-router';
@@ -8,6 +9,7 @@ import { reduxForm } from 'redux-form';
89
import { Helmet } from 'react-helmet';
910
import * as UserActions from '../actions';
1011
import ResetPasswordForm from '../components/ResetPasswordForm';
12+
import { validateResetPassword } from '../../../utils/reduxFormUtils';
1113

1214
const exitUrl = require('../../../images/exit.svg');
1315
const logoUrl = require('../../../images/p5js-logo.svg');
@@ -80,16 +82,8 @@ function mapDispatchToProps(dispatch) {
8082
return bindActionCreators(UserActions, dispatch);
8183
}
8284

83-
function validate(formProps) {
84-
const errors = {};
85-
if (!formProps.email) {
86-
errors.email = 'Please enter an email';
87-
}
88-
return errors;
89-
}
90-
9185
export default reduxForm({
9286
form: 'reset-password',
9387
fields: ['email'],
94-
validate
88+
validate: validateResetPassword
9589
}, mapStateToProps, mapDispatchToProps)(ResetPasswordView);

client/utils/reduxFormUtils.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export const domOnlyProps = ({
1515
...domProps }) => domProps;
1616
/* eslint-enable */
1717

18+
// eslint-disable-next-line max-len
19+
const EMAIL_REGEX = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i;
20+
1821
function validateNameEmail(formProps, errors) {
1922
if (!formProps.username) {
2023
errors.username = 'Please enter a username.';
@@ -28,7 +31,7 @@ function validateNameEmail(formProps, errors) {
2831
errors.email = 'Please enter an email.';
2932
} else if (
3033
// eslint-disable-next-line max-len
31-
!formProps.email.match(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i)) {
34+
!formProps.email.match(EMAIL_REGEX)) {
3235
errors.email = 'Please enter a valid email address.';
3336
}
3437
}
@@ -79,3 +82,14 @@ export function validateSignup(formProps) {
7982

8083
return errors;
8184
}
85+
export function validateResetPassword(formProps) {
86+
const errors = {};
87+
if (!formProps.email) {
88+
errors.email = 'Please enter an email.';
89+
} else if (
90+
// eslint-disable-next-line max-len
91+
!formProps.email.match(EMAIL_REGEX)) {
92+
errors.email = 'Please enter a valid email address.';
93+
}
94+
return errors;
95+
}

0 commit comments

Comments
 (0)