forked from UitsHabib/shop-on
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50a559c
commit 27facbf
Showing
5 changed files
with
86 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,51 @@ | ||
const { object, string, ref } = require('yup'); | ||
const { object, string, ref } = require("yup"); | ||
|
||
const isEmailLengthValid = email => { | ||
const isEmailLengthValid = (email) => { | ||
if (!email) return false; | ||
const part = email.split('@'); | ||
const part = email.split("@"); | ||
const emailParts = part[0]; | ||
return emailParts.length <= 64; | ||
} | ||
}; | ||
|
||
const customerRegisterSchema = object().shape({ | ||
username: string() | ||
.min(3, 'Username must be at least 3 characters.') | ||
.max(50, 'Username must be at most 50 character long.') | ||
.required('Username is required.'), | ||
.min(3, "Username must be at least 3 characters.") | ||
.max(50, "Username must be at most 50 character long.") | ||
.required("Username is required."), | ||
email: string() | ||
.email('This field should be a valid email address.') | ||
.max(100, 'Email must be at most 100 characters long.') | ||
.required('Email is required.') | ||
.test('is-valid-email-length', 'The part before @ of the email can be maximum 64 characters.', | ||
email => isEmailLengthValid(email)), | ||
.email("This field should be a valid email address.") | ||
.max(100, "Email must be at most 100 characters long.") | ||
.required("Email is required.") | ||
.test( | ||
"is-valid-email-length", | ||
"The part before @ of the email can be maximum 64 characters.", | ||
(email) => isEmailLengthValid(email) | ||
), | ||
password: string() | ||
.min(8, 'The password must be at least 8 characters long.') | ||
.max(50, 'The password must be at most 50 characters long.') | ||
.required('Password is required.'), | ||
.min(8, "The password must be at least 8 characters long.") | ||
.max(50, "The password must be at most 50 characters long.") | ||
.required("Password is required."), | ||
confirm_password: string() | ||
.required('Confirm Password is required') | ||
.oneOf([ref('password'), null], 'Password and Confirm Password must should be matched') | ||
.required("Confirm Password is required") | ||
.oneOf( | ||
[ref("password"), null], | ||
"Password and Confirm Password must should be matched" | ||
), | ||
}); | ||
|
||
const customerUpdateSchema = object().shape({ | ||
username: string() | ||
.min(3, 'Username must be at least 3 characters.') | ||
.max(50, 'Username must be at most 50 characters long.'), | ||
.min(3, "Username must be at least 3 characters.") | ||
.max(50, "Username must be at most 50 characters long."), | ||
email: string() | ||
.email('This field should be a valid email address.') | ||
.max(100, 'Email must be at most 100 characters long.') | ||
.test('is-valid-email-length', 'The part before @ of the email can be maximum 64 characters.', | ||
email => isEmailLengthValid(email)) | ||
.email("This field should be a valid email address.") | ||
.max(100, "Email must be at most 100 characters long.") | ||
.test( | ||
"is-valid-email-length", | ||
"The part before @ of the email can be maximum 64 characters.", | ||
(email) => isEmailLengthValid(email) | ||
), | ||
}); | ||
|
||
module.exports.customerRegisterSchema = customerRegisterSchema; | ||
module.exports.customerUpdateSchema = customerUpdateSchema; | ||
module.exports.customerUpdateSchema = customerUpdateSchema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters