Email Validation added (#1120)

* changes

* changes

* changes

* changes

* changes
This commit is contained in:
Apoorv Taneja 2019-07-23 23:46:05 +05:30 committed by Cassie Tarakajian
parent 7fdd970a43
commit 4c1ebdf83d
3 changed files with 19 additions and 10 deletions

View file

@ -17,6 +17,7 @@ function ResetPasswordForm(props) {
id="email" id="email"
{...domOnlyProps(email)} {...domOnlyProps(email)}
/> />
{email.touched && email.error && <span className="form-error">{email.error}</span>}
</p> </p>
<input <input
type="submit" type="submit"

View file

@ -1,3 +1,4 @@
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import React from 'react'; import React from 'react';
import { Link, browserHistory } from 'react-router'; import { Link, browserHistory } from 'react-router';
@ -8,6 +9,7 @@ import { reduxForm } from 'redux-form';
import { Helmet } from 'react-helmet'; import { Helmet } from 'react-helmet';
import * as UserActions from '../actions'; import * as UserActions from '../actions';
import ResetPasswordForm from '../components/ResetPasswordForm'; import ResetPasswordForm from '../components/ResetPasswordForm';
import { validateResetPassword } from '../../../utils/reduxFormUtils';
const exitUrl = require('../../../images/exit.svg'); const exitUrl = require('../../../images/exit.svg');
const logoUrl = require('../../../images/p5js-logo.svg'); const logoUrl = require('../../../images/p5js-logo.svg');
@ -80,16 +82,8 @@ function mapDispatchToProps(dispatch) {
return bindActionCreators(UserActions, dispatch); return bindActionCreators(UserActions, dispatch);
} }
function validate(formProps) {
const errors = {};
if (!formProps.email) {
errors.email = 'Please enter an email';
}
return errors;
}
export default reduxForm({ export default reduxForm({
form: 'reset-password', form: 'reset-password',
fields: ['email'], fields: ['email'],
validate validate: validateResetPassword
}, mapStateToProps, mapDispatchToProps)(ResetPasswordView); }, mapStateToProps, mapDispatchToProps)(ResetPasswordView);

View file

@ -15,6 +15,9 @@ export const domOnlyProps = ({
...domProps }) => domProps; ...domProps }) => domProps;
/* eslint-enable */ /* eslint-enable */
// eslint-disable-next-line max-len
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;
function validateNameEmail(formProps, errors) { function validateNameEmail(formProps, errors) {
if (!formProps.username) { if (!formProps.username) {
errors.username = 'Please enter a username.'; errors.username = 'Please enter a username.';
@ -28,7 +31,7 @@ function validateNameEmail(formProps, errors) {
errors.email = 'Please enter an email.'; errors.email = 'Please enter an email.';
} else if ( } else if (
// eslint-disable-next-line max-len // eslint-disable-next-line max-len
!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)) { !formProps.email.match(EMAIL_REGEX)) {
errors.email = 'Please enter a valid email address.'; errors.email = 'Please enter a valid email address.';
} }
} }
@ -79,3 +82,14 @@ export function validateSignup(formProps) {
return errors; return errors;
} }
export function validateResetPassword(formProps) {
const errors = {};
if (!formProps.email) {
errors.email = 'Please enter an email.';
} else if (
// eslint-disable-next-line max-len
!formProps.email.match(EMAIL_REGEX)) {
errors.email = 'Please enter a valid email address.';
}
return errors;
}