Skip to content

Commit 2672a65

Browse files
committed
validation for username now accepts both email and username
1 parent 888aec2 commit 2672a65

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

react-app/src/components/LemmaForm/LemmaForm.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ import {
1414
} from 'reactstrap';
1515
import { IoMdTrash } from 'react-icons/io';
1616
import './LemmaForm.css';
17-
import { isNotRef, isNotOwner, isUrl } from '../../helpers/input-validation';
17+
import {
18+
isNotRef,
19+
isNotOwner,
20+
isUrl,
21+
isEmail
22+
} from '../../helpers/input-validation';
1823
import {
1924
RECAPTCHA_CLIENT_KEY,
2025
BASE_URL,
@@ -158,7 +163,11 @@ const LemmaForm = (props: any) => {
158163
: setUrl({ link: val, invalid: true });
159164
};
160165
const handleOwner = (input: EventTarget & HTMLInputElement) => {
161-
if (isNotOwner.test(input.value) && input.id === 'name') {
166+
if (
167+
((isNotOwner.test(input.value) && !isEmail.test(input.value)) ||
168+
(!isNotOwner.test(input.value) && isEmail.test(input.value))) &&
169+
input.id === 'name'
170+
) {
162171
setOwner({ ...owner, [input.id]: input.value, invalid: true });
163172
} else {
164173
setOwner({ ...owner, [input.id]: input.value, invalid: false });
@@ -260,7 +269,7 @@ const LemmaForm = (props: any) => {
260269
onChange={e => handleOwner(e.target)}
261270
/>
262271
<FormFeedback invalid="">
263-
Username must not contain (@, /, or whitespace)
272+
Username must be an valid email or username
264273
</FormFeedback>
265274
</FormGroup>
266275
</Col>

0 commit comments

Comments
 (0)