@@ -14,6 +14,7 @@ import {
1414} from "../../constants"
1515import FormError from "./elements/FormError"
1616import CardLabel from "../input/CardLabel"
17+ import { usernameFieldErrorMessage } from "../../lib/validation"
1718
1819export const NAME_REGEX =
1920 / ^ (? ! [ ~ ! @ & ) ( + : ' . ? , - ] ) (? ! .* [ ( / ^ $ # * = [ \] ` % _ ; \\ < > { } " | ) ] ) .* $ /
@@ -25,7 +26,17 @@ export const NAME_REGEX_FAIL_MESSAGE =
2526 "Name cannot start with a special character (~!@&)(+:'.?,-), and cannot contain any of (/^$#*=[]`%_;\\<>{}\"|)"
2627
2728export const legalAddressValidation = yup . object ( ) . shape ( {
28- name : yup . string ( ) . required ( ) . label ( "Full Name" ) . min ( 2 ) . max ( 254 ) ,
29+ name : yup . string ( ) . required ( ) . label ( "Full Name" ) . min ( 2 ) . max ( 254 ) ,
30+ username : yup
31+ . string ( )
32+ . required ( )
33+ . label ( "Public Username" )
34+ . min ( 3 , usernameFieldErrorMessage )
35+ . max ( 30 , usernameFieldErrorMessage )
36+ . matches (
37+ / ^ [ ^ ! @ # $ % ^ & * ( ) + = \[ \] { } ; ' : " \\ | , < > \/ ? ~ ] * $ / , // eslint-disable-line no-useless-escape
38+ "Username cannot contain any of these !@#$%^&*()+=[]{};':\"\\|,<>/?~ symbols"
39+ ) ,
2940 legal_address : yup . object ( ) . shape ( {
3041 first_name : yup
3142 . string ( )
@@ -231,30 +242,27 @@ export const LegalAddressFields = ({
231242 />
232243 < ErrorMessage name = "name" component = { FormError } />
233244 </ div >
234- { isNewAccount ? (
235- < React . Fragment >
236- < div className = "form-group" >
237- < CardLabel
238- htmlFor = "username"
239- isRequired = { true }
240- label = "Public Username"
241- subLabel = "Name that will identify you in courses"
242- />
243- < Field
244- type = "text"
245- name = "username"
246- className = "form-control"
247- autoComplete = "username"
248- id = "username"
249- aria-invalid = { errors . username ? "true" : null }
250- aria-describedby = { errors . username ? "username-error" : null }
251- aria-description = "Name that will identify you in courses."
252- required
253- />
254- < ErrorMessage name = "username" component = { FormError } />
255- </ div >
256- </ React . Fragment >
257- ) : null }
245+
246+ < div className = "form-group" >
247+ < CardLabel
248+ htmlFor = "username"
249+ isRequired = { true }
250+ label = "Public Username"
251+ subLabel = "Name that will identify you in courses"
252+ />
253+ < Field
254+ type = "text"
255+ name = "username"
256+ className = "form-control"
257+ autoComplete = "username"
258+ id = "username"
259+ aria-invalid = { errors . username ? "true" : null }
260+ aria-describedby = { errors . username ? "username-error" : null }
261+ aria-description = "Name that will identify you in courses."
262+ required
263+ />
264+ < ErrorMessage name = "username" component = { FormError } />
265+ </ div >
258266 < div className = "form-group" >
259267 < CardLabel
260268 htmlFor = "legal_address.country"
0 commit comments