Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

behnaz/affiliate-signup #7833

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ const AccountDetails = ({

const handleInput = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
const { name, value } = e.target
setFormData((prev) => ({ ...prev, [name]: value }))
setFormData((prev) => ({ ...prev, [name]: value.replace(/ +/g, " ") }))
if (affiliate_validation[name]) {
const error_msg = affiliate_validation[name](value) || ''
setFormErrors((errors) => ({
Expand All @@ -172,6 +172,11 @@ const AccountDetails = ({
}
}, [])

const handleInputTrim = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
const { name, value } = e.target
setFormData((prev) => ({ ...prev, [name]: value.trim() }))
}, [])

const handleError = (item) => {
setFormData((prev) => ({ ...prev, [item.name]: '' }))
setFormErrors((errors) => ({
Expand Down Expand Up @@ -229,7 +234,7 @@ const AccountDetails = ({
placeholder={item.label}
password_icon={item.type == 'password'}
onChange={handleInput}
onBlur={handleInput}
onBlur={handleInputTrim}
data-lpignore="true"
handleError={() => handleError(item)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const affiliate_validation_regex = {
email: (value: string) => /^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$/.test(value),
latin: (value: string) => /[^a-zA-Za 0-9-]/.test(value),
name: (value: string) =>
/^(?!.*\s{2,})[\p{L}\s'.-]{2,50}$/u.test(value) &&
/^(?!.*\s{2,})[\p{L}\s'.-]{2,50}$/u.test(value.trim()) &&
value.trim().length >= 2 &&
value.trim().length <= 50,
phone: (value: string) => /^\+?\d+$/.test(value),
Expand Down Expand Up @@ -47,9 +47,8 @@ const nameValidation = (input: string, text: string) => {
if (!input) {
return text + localize('_t_ is required_t_')
} else if (
input.length < 2 ||
input.length > 50 ||
!affiliate_validation_regex.non_empty_string(input)
input.trim().length < 2 ||
input.trim().length > 50
) {
return localize('_t_You should enter 2-50 characters._t_')
} else if (affiliate_validation_regex.latin(input) || !affiliate_validation_regex.name(input)) {
Expand Down
Loading