feat: Optimize validate message (#290)

* feat: Optimize validate message

* feat: Optimize validate message
This commit is contained in:
Zhaoxinxin 2023-09-11 15:26:15 +08:00 committed by GitHub
parent 5e1a13d300
commit 35dedfd357
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 44 additions and 48 deletions

View File

@ -101,7 +101,7 @@ export default function EditCluster() {
autoComplete: 'family-name', autoComplete: 'family-name',
value: bio, value: bio,
placeholder: 'Please enter description', placeholder: 'Please enter description',
helperText: bioError ? 'The length is 1-1000' : '', helperText: bioError ? 'Fill in the characters, the length is 0-1000.' : '',
error: bioError, error: bioError,
onChange: (e: any) => { onChange: (e: any) => {
@ -128,7 +128,7 @@ export default function EditCluster() {
autoComplete: 'family-name', autoComplete: 'family-name',
placeholder: 'Please enter Location', placeholder: 'Please enter Location',
value: location, value: location,
helperText: locationError ? 'Maximum length is 100' : '', helperText: locationError ? 'Fill in the characters, the length is 0-100.' : '',
error: locationError, error: locationError,
onChange: (e: any) => { onChange: (e: any) => {
@ -184,7 +184,7 @@ export default function EditCluster() {
name: 'idc', name: 'idc',
placeholder: 'Please enter IDC', placeholder: 'Please enter IDC',
error: idcError, error: idcError,
helperText: idcError ? 'Maximum length is 100' : '', helperText: idcError ? 'Fill in the characters, the length is 0-100.' : '',
onKeyDown: (e: any) => { onKeyDown: (e: any) => {
if (e.keyCode === 13) { if (e.keyCode === 13) {
@ -228,7 +228,7 @@ export default function EditCluster() {
name: 'cidrs', name: 'cidrs',
placeholder: 'Please enter CIDRs', placeholder: 'Please enter CIDRs',
error: cidrsError, error: cidrsError,
helperText: cidrsError ? 'Maximum length is 1000' : '', helperText: cidrsError ? 'Fill in the characters, the length is 0-1000.' : '',
onKeyDown: (e: any) => { onKeyDown: (e: any) => {
if (e.keyCode === 13) { if (e.keyCode === 13) {
@ -256,7 +256,7 @@ export default function EditCluster() {
autoComplete: 'family-name', autoComplete: 'family-name',
placeholder: 'Please enter Seed Peer load limit', placeholder: 'Please enter Seed Peer load limit',
value: seed_peer_cluster_config?.load_limit, value: seed_peer_cluster_config?.load_limit,
helperText: seedPeerLoadLimitError ? 'Must be a number and range from 0-5000' : '', helperText: seedPeerLoadLimitError ? 'Fill in the number, the length is 0-5000.' : '',
error: seedPeerLoadLimitError, error: seedPeerLoadLimitError,
onChange: (e: any) => { onChange: (e: any) => {
@ -293,7 +293,7 @@ export default function EditCluster() {
type: 'number', type: 'number',
autoComplete: 'family-name', autoComplete: 'family-name',
placeholder: 'Please enter Peer load limit', placeholder: 'Please enter Peer load limit',
helperText: peerLoadLimitError ? 'Must be a number and range from 0-2000' : '', helperText: peerLoadLimitError ? 'Fill in the number, the length is 0-2000.' : '',
error: peerLoadLimitError, error: peerLoadLimitError,
value: load_limit, value: load_limit,
@ -334,7 +334,7 @@ export default function EditCluster() {
autoComplete: 'family-name', autoComplete: 'family-name',
placeholder: 'Please enter Number of concurrent download pieces', placeholder: 'Please enter Number of concurrent download pieces',
value: concurrent_piece_count, value: concurrent_piece_count,
helperText: numberOfConcurrentDownloadPiecesError ? 'Must be a number and range from 0-50' : '', helperText: numberOfConcurrentDownloadPiecesError ? 'Fill in the number, the length is 0-50.' : '',
error: numberOfConcurrentDownloadPiecesError, error: numberOfConcurrentDownloadPiecesError,
onChange: (e: any) => { onChange: (e: any) => {
@ -373,7 +373,7 @@ export default function EditCluster() {
autoComplete: 'family-name', autoComplete: 'family-name',
placeholder: 'Please enter Candidate parent limit', placeholder: 'Please enter Candidate parent limit',
value: candidate_parent_limit, value: candidate_parent_limit,
helperText: candidateParentLimitError ? 'Must be a number and range from 1-20' : '', helperText: candidateParentLimitError ? 'Fill in the number, the length is 1-20.' : '',
error: candidateParentLimitError, error: candidateParentLimitError,
onChange: (e: any) => { onChange: (e: any) => {
@ -415,7 +415,7 @@ export default function EditCluster() {
autoComplete: 'family-name', autoComplete: 'family-name',
placeholder: 'Please enter Filter parent limit', placeholder: 'Please enter Filter parent limit',
value: filter_parent_limit, value: filter_parent_limit,
helperText: filterParentLimitError ? 'Must be a number and range from 10-1000' : '', helperText: filterParentLimitError ? 'Fill in the number, the length is 10-1000.' : '',
error: filterParentLimitError, error: filterParentLimitError,
onChange: (e: any) => { onChange: (e: any) => {

View File

@ -49,7 +49,7 @@ export default function NewCluster() {
name: 'name', name: 'name',
autoComplete: 'family-name', autoComplete: 'family-name',
placeholder: 'Enter your name', placeholder: 'Enter your name',
helperText: nameError ? 'The length is 1-40' : '', helperText: nameError ? 'Fill in the characters, the length is 1-40.' : '',
error: nameError, error: nameError,
onChange: (e: any) => { onChange: (e: any) => {
@ -60,7 +60,7 @@ export default function NewCluster() {
setError: setNameError, setError: setNameError,
validate: (value: string) => { validate: (value: string) => {
const reg = /^(?=.*[A-Za-z0-9@$!%*?&._-])[A-Za-z0-9@$!%*?&._-]{1,}$/; const reg = /^(?=.*[A-Za-z0-9@$!%*?&._-])[A-Za-z0-9@$!%*?&._-]{1,40}$/;
return reg.test(value); return reg.test(value);
}, },
}, },
@ -71,7 +71,7 @@ export default function NewCluster() {
name: 'description', name: 'description',
autoComplete: 'family-name', autoComplete: 'family-name',
placeholder: 'Enter a cluster description', placeholder: 'Enter a cluster description',
helperText: bioError ? 'The length is 1-1000' : '', helperText: bioError ? 'Fill in the characters, the length is 0-1000.' : '',
error: bioError, error: bioError,
onChange: (e: any) => { onChange: (e: any) => {
@ -96,7 +96,7 @@ export default function NewCluster() {
name: 'location', name: 'location',
autoComplete: 'family-name', autoComplete: 'family-name',
placeholder: 'Please enter location', placeholder: 'Please enter location',
helperText: locationError ? 'Maximum length is 100' : '', helperText: locationError ? 'Fill in the characters, the length is 0-100.' : '',
error: locationError, error: locationError,
onChange: (e: any) => { onChange: (e: any) => {
@ -150,7 +150,7 @@ export default function NewCluster() {
name: 'idc', name: 'idc',
placeholder: 'Please enter IDC', placeholder: 'Please enter IDC',
error: idcError, error: idcError,
helperText: idcError ? 'Maximum length is 100' : '', helperText: idcError ? 'Fill in the characters, the length is 0-100.' : '',
onKeyDown: (e: any) => { onKeyDown: (e: any) => {
if (e.keyCode === 13) { if (e.keyCode === 13) {
@ -196,7 +196,7 @@ export default function NewCluster() {
name: 'cidrs', name: 'cidrs',
placeholder: 'Please enter CIDRs', placeholder: 'Please enter CIDRs',
error: cidrsError, error: cidrsError,
helperText: cidrsError ? 'Maximum length is 1000' : '', helperText: cidrsError ? 'Fill in the characters, the length is 0-1000.' : '',
onKeyDown: (e: any) => { onKeyDown: (e: any) => {
if (e.keyCode === 13) { if (e.keyCode === 13) {
@ -225,7 +225,7 @@ export default function NewCluster() {
autoComplete: 'family-name', autoComplete: 'family-name',
placeholder: 'Please enter Seed Peer load limit', placeholder: 'Please enter Seed Peer load limit',
defaultValue: 300, defaultValue: 300,
helperText: seedPeerLoadLimitError ? 'Must be a number and range from 0-5000' : '', helperText: seedPeerLoadLimitError ? 'Fill in the number, the length is 0-5000.' : '',
error: seedPeerLoadLimitError, error: seedPeerLoadLimitError,
onChange: (e: any) => { onChange: (e: any) => {
@ -260,7 +260,7 @@ export default function NewCluster() {
autoComplete: 'family-name', autoComplete: 'family-name',
placeholder: 'Please enter Peer load limit', placeholder: 'Please enter Peer load limit',
defaultValue: 50, defaultValue: 50,
helperText: peerLoadLimitError ? 'Must be a number and range from 0-2000' : '', helperText: peerLoadLimitError ? 'Fill in the number, the length is 0-2000.' : '',
error: peerLoadLimitError, error: peerLoadLimitError,
onChange: (e: any) => { onChange: (e: any) => {
@ -297,7 +297,7 @@ export default function NewCluster() {
autoComplete: 'family-name', autoComplete: 'family-name',
placeholder: 'Please enter Number of concurrent download pieces', placeholder: 'Please enter Number of concurrent download pieces',
defaultValue: 4, defaultValue: 4,
helperText: numberOfConcurrentDownloadPiecesError ? 'Must be a number and range from 0-2000' : '', helperText: numberOfConcurrentDownloadPiecesError ? 'Fill in the number, the length is 0-50.' : '',
error: numberOfConcurrentDownloadPiecesError, error: numberOfConcurrentDownloadPiecesError,
onChange: (e: any) => { onChange: (e: any) => {
@ -332,7 +332,7 @@ export default function NewCluster() {
autoComplete: 'family-name', autoComplete: 'family-name',
placeholder: 'Please enter Candidate parent limit', placeholder: 'Please enter Candidate parent limit',
defaultValue: 4, defaultValue: 4,
helperText: candidateParentLimitError ? 'Must be a number and range from 1-20' : '', helperText: candidateParentLimitError ? 'Fill in the number, the length is 1-20.' : '',
error: candidateParentLimitError, error: candidateParentLimitError,
onChange: (e: any) => { onChange: (e: any) => {
@ -368,7 +368,7 @@ export default function NewCluster() {
placeholder: 'Please enter Filter parent limit', placeholder: 'Please enter Filter parent limit',
defaultValue: 40, defaultValue: 40,
fullWidth: false, fullWidth: false,
helperText: filterParentLimitError ? 'Must be a number and range from 10-1000' : '', helperText: filterParentLimitError ? 'Fill in the number, the length is 10-1000.' : '',
error: filterParentLimitError, error: filterParentLimitError,
onChange: (e: any) => { onChange: (e: any) => {

View File

@ -59,7 +59,7 @@ export default function UpdateTokens() {
autoComplete: 'family-name', autoComplete: 'family-name',
placeholder: 'Enter your description', placeholder: 'Enter your description',
value: tokens.bio, value: tokens.bio,
helperText: bioError ? 'The length is 1-1000' : '', helperText: bioError ? 'Fill in the characters, the length is 0-1000.' : '',
error: bioError, error: bioError,
InputProps: { InputProps: {

View File

@ -57,7 +57,7 @@ export default function CreateTokens() {
name: 'name', name: 'name',
autoComplete: 'family-name', autoComplete: 'family-name',
placeholder: 'Enter your token name', placeholder: 'Enter your token name',
helperText: nameError ? 'Please enter the correct token name' : '', helperText: nameError ? 'Fill in the characters, the length is 1-100.' : '',
error: nameError, error: nameError,
InputProps: { InputProps: {
endAdornment: ( endAdornment: (
@ -78,7 +78,7 @@ export default function CreateTokens() {
setError: setNameError, setError: setNameError,
validate: (value: string) => { validate: (value: string) => {
const reg = /^(?=.*[A-Za-z0-9@$!%*?&._-])[A-Za-z0-9@$!%*?&._-]{1,}$/; const reg = /^(?=.*[A-Za-z0-9@$!%*?&._-])[A-Za-z0-9@$!%*?&._-]{1,100}$/;
return reg.test(value); return reg.test(value);
}, },
}, },
@ -89,7 +89,7 @@ export default function CreateTokens() {
name: 'bio', name: 'bio',
autoComplete: 'family-name', autoComplete: 'family-name',
placeholder: 'Enter your description', placeholder: 'Enter your description',
helperText: bioError ? 'The length is 1-1000' : '', helperText: bioError ? 'Fill in the characters, the length is 0-1000.' : '',
error: bioError, error: bioError,
InputProps: { InputProps: {
endAdornment: ( endAdornment: (

View File

@ -133,8 +133,8 @@ export default function Profile() {
name: 'bio', name: 'bio',
multiline: true, multiline: true,
autoComplete: 'family-name', autoComplete: 'family-name',
placeholder: 'Enter your Bio', placeholder: 'Enter your description',
helperText: bioError ? 'The length is 0-1000' : '', helperText: bioError ? 'Fill in the characters, the length is 0-1000.' : '',
error: bioError, error: bioError,
value: user.bio, value: user.bio,
@ -169,7 +169,7 @@ export default function Profile() {
autoComplete: 'family-name', autoComplete: 'family-name',
value: user.phone, value: user.phone,
placeholder: 'Enter your Phone', placeholder: 'Enter your Phone',
helperText: phoneError ? 'Please enter the correct phone number' : '', helperText: phoneError ? 'Invalid phone number.' : '',
error: phoneError, error: phoneError,
onChange: (e: any) => { onChange: (e: any) => {
@ -202,7 +202,7 @@ export default function Profile() {
autoComplete: 'family-name', autoComplete: 'family-name',
value: user.location, value: user.location,
placeholder: 'Enter your location', placeholder: 'Enter your location',
helperText: locationError ? 'Please enter your address' : '', helperText: locationError ? 'Fill in the characters, the length is 0-100.' : '',
error: locationError, error: locationError,
onChange: (e: any) => { onChange: (e: any) => {
@ -222,7 +222,7 @@ export default function Profile() {
setError: setLocationError, setError: setLocationError,
validate: (value: string) => { validate: (value: string) => {
const reg = /^[A-Za-z0-9]{0,1000}$/; const reg = /^[A-Za-z0-9]{0,100}$/;
return reg.test(value); return reg.test(value);
}, },
}, },
@ -234,7 +234,7 @@ export default function Profile() {
autoComplete: 'family-name', autoComplete: 'family-name',
value: user.email, value: user.email,
placeholder: 'Enter your Email', placeholder: 'Enter your Email',
helperText: emailError ? 'Please enter the correct email format' : '', helperText: emailError ? 'Email is invalid or already taken.' : '',
error: emailError, error: emailError,
onChange: (e: any) => { onChange: (e: any) => {
@ -270,7 +270,7 @@ export default function Profile() {
type: showOldPassword ? 'text' : 'password', type: showOldPassword ? 'text' : 'password',
placeholder: 'Enter your old password', placeholder: 'Enter your old password',
value: old_password, value: old_password,
helperText: phoneError ? 'Please enter the correct password' : '', helperText: phoneError ? 'Fill in the characters, the maximum length is 16.' : '',
error: phoneError, error: phoneError,
onChange: (e: any) => { onChange: (e: any) => {
@ -314,9 +314,7 @@ export default function Profile() {
type: showNewPassword ? 'text' : 'password', type: showNewPassword ? 'text' : 'password',
autoComplete: 'family-name', autoComplete: 'family-name',
placeholder: 'Enter your new password', placeholder: 'Enter your new password',
helperText: locationError helperText: locationError ? `At least 8-16 characters, with at least 1 lowercase letter and 1 number.` : '',
? 'At least 8-16 characters, at least 1 uppercase letter, 1 lowercase letter, and 1 number'
: '',
error: locationError, error: locationError,
value: new_password, value: new_password,
@ -349,7 +347,7 @@ export default function Profile() {
syncError: false, syncError: false,
setError: setLocationError, setError: setLocationError,
validate: (value: string) => { validate: (value: string) => {
const reg = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{8,16}$/; const reg = /^(?=.*[a-z])(?=.*\d)[^]{8,16}$/;
return reg.test(value); return reg.test(value);
}, },
}, },
@ -361,7 +359,7 @@ export default function Profile() {
type: showConfirmPassword ? 'text' : 'password', type: showConfirmPassword ? 'text' : 'password',
autoComplete: 'family-name', autoComplete: 'family-name',
placeholder: 'Enter your payload', placeholder: 'Enter your payload',
helperText: emailError ? 'Please enter the same password' : '', helperText: emailError ? 'Please enter the same password.' : '',
error: emailError, error: emailError,
onChange: (e: any) => { onChange: (e: any) => {
@ -392,7 +390,7 @@ export default function Profile() {
setError: setEmailError, setError: setEmailError,
validate: (value: string) => { validate: (value: string) => {
const reg = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{8,16}$/; const reg = /^(?=.*[a-z])(?=.*\d)[^]{8,16}$/;
return value === newPassword && reg.test(value); return value === newPassword && reg.test(value);
}, },
}, },

View File

@ -35,7 +35,7 @@ export default function SignIn() {
name: 'account', name: 'account',
autoComplete: 'family-name', autoComplete: 'family-name',
placeholder: 'Enter your account', placeholder: 'Enter your account',
helperText: accountError ? 'Please enter the correct account number' : '', helperText: accountError ? 'Fill in the characters, the length is 3-10.' : '',
error: accountError, error: accountError,
onChange: (e: any) => { onChange: (e: any) => {
@ -58,7 +58,7 @@ export default function SignIn() {
type: showPassword ? 'text' : 'password', type: showPassword ? 'text' : 'password',
autoComplete: 'password', autoComplete: 'password',
placeholder: 'Enter your password', placeholder: 'Enter your password',
helperText: passwordError ? 'Please enter the correct password ' : '', helperText: passwordError ? 'Fill in the characters, the maximum length is 16.' : '',
error: passwordError, error: passwordError,
onChange: (e: any) => { onChange: (e: any) => {

View File

@ -40,7 +40,7 @@ export default function SignUp() {
id: 'account', id: 'account',
placeholder: 'Enter your account', placeholder: 'Enter your account',
error: accountError, error: accountError,
helperText: accountError ? 'At least four characters do not contain special characters' : '', helperText: accountError ? 'Fill in the characters, the length is 3-10.' : '',
onChange: (e: any) => { onChange: (e: any) => {
changeValidate(e.target.value, formList[0]); changeValidate(e.target.value, formList[0]);
@ -62,7 +62,7 @@ export default function SignUp() {
id: 'email', id: 'email',
placeholder: 'Enter your email', placeholder: 'Enter your email',
error: emailError, error: emailError,
helperText: emailError ? 'Enter the correct email' : '', helperText: emailError ? 'Email is invalid or already taken.' : '',
onChange: (e: any) => { onChange: (e: any) => {
changeValidate(e.target.value, formList[1]); changeValidate(e.target.value, formList[1]);
@ -83,9 +83,7 @@ export default function SignUp() {
id: 'password', id: 'password',
placeholder: 'Enter your password', placeholder: 'Enter your password',
autoComplete: 'new-password', autoComplete: 'new-password',
helperText: passwordError helperText: passwordError ? `At least 8-16 characters, with at least 1 lowercase letter and 1 number.` : '',
? 'At least 8-16 characters, at least 1 uppercase letter, 1 lowercase letter, and 1 number'
: '',
type: showPassword ? 'text' : 'password', type: showPassword ? 'text' : 'password',
error: passwordError, error: passwordError,
InputProps: { InputProps: {
@ -112,7 +110,7 @@ export default function SignUp() {
setError: setPasswordError, setError: setPasswordError,
validate: (value: string) => { validate: (value: string) => {
const reg = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{8,16}$/; const reg = /^(?=.*[a-z])(?=.*\d)[^]{8,16}$/;
return reg.test(value); return reg.test(value);
}, },
}, },
@ -125,7 +123,7 @@ export default function SignUp() {
autoComplete: 'new-password', autoComplete: 'new-password',
placeholder: 'Repeat your new password', placeholder: 'Repeat your new password',
error: confirmPassworError, error: confirmPassworError,
helperText: confirmPassworError ? 'Please enter the same password' : '', helperText: confirmPassworError ? 'Please enter the same password.' : '',
InputProps: { InputProps: {
endAdornment: ( endAdornment: (
@ -152,7 +150,7 @@ export default function SignUp() {
setError: setConfirmPassworError, setError: setConfirmPassworError,
validate: (value: string) => { validate: (value: string) => {
const reg = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{8,16}$/; const reg = /^(?=.*[a-z])(?=.*\d)[^]{8,16}$/;
return value === password && reg.test(value); return value === password && reg.test(value);
}, },
}, },