Skip to content

Commit

Permalink
✨ feat: Make the validations of the signUp and logIn forms
Browse files Browse the repository at this point in the history
  • Loading branch information
akramhany committed Dec 29, 2023
1 parent 8b1ac40 commit add3758
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
4 changes: 4 additions & 0 deletions client/src/components/common/Inputs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ function TextInput({
onChange,
placeholder,
required,
pattern,
onInvalid,
}) {
return (
<label className="input input--text">
Expand All @@ -21,6 +23,8 @@ function TextInput({
value={value}
onChange={onChange}
required={required}
pattern={pattern}
onInvalid={onInvalid}
/>
</label>
);
Expand Down
4 changes: 3 additions & 1 deletion client/src/components/login/logIn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export default function LogIn() {
name="email"
value={email}
placeholder="[email protected]"
onChange={(e) => setEmail(e.target.value)}
onChange={(e) => {setEmail(e.target.value); e.target.setCustomValidity('');}}
pattern="^[a-zA-Z0-9._%\+\-]+@[a-zA-Z0-9._%\+\-]+\.[a-z]{2,}$"
onInvalid={(e) => e.target.setCustomValidity('الرجاء إدخال بريد إليكتروني صحيح')}
required={true}
/>
<TextInput
Expand Down
20 changes: 15 additions & 5 deletions client/src/components/signup/signUp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ export default function SignUp() {
name="firstName"
value={firstName}
placeholder="أكتب أسمك الاول"
onChange={(e) => setFirstName(e.target.value)}
onChange={(e) => {setFirstName(e.target.value); e.target.setCustomValidity('');}}
pattern="^[\u0621-\u064Aa-zA-Z]+$"
onInvalid={(e) => e.target.setCustomValidity('الرجاء إدخال الاسم الاول فقط (باللغة العربية او الانجليزية)')}
required={true}
/>
<TextInput
Expand All @@ -89,7 +91,9 @@ export default function SignUp() {
name="middleName"
value={middleName}
placeholder="أكتب أسمك المتوسط"
onChange={(e) => setMiddleName(e.target.value)}
onChange={(e) => {setMiddleName(e.target.value); e.target.setCustomValidity('');}}
pattern="^[\u0621-\u064Aa-zA-Z]+$"
onInvalid={(e) => e.target.setCustomValidity('الرجاء إدخال الاسم الاوسط فقط (باللغة العربية او الانجليزية)')}
required={true}
/>
<TextInput
Expand All @@ -98,7 +102,9 @@ export default function SignUp() {
name="lastName"
value={lastName}
placeholder="أكتب أسمك الأخير"
onChange={(e) => setLastName(e.target.value)}
onChange={(e) => {setLastName(e.target.value); e.target.setCustomValidity('');}}
pattern="^[\u0621-\u064Aa-zA-Z]+$"
onInvalid={(e) => e.target.setCustomValidity('الرجاء إدخال الاسم الأخير فقط (باللغة العربية او الانجليزية)')}
required={true}
/>
</div>
Expand All @@ -110,7 +116,9 @@ export default function SignUp() {
name="email"
value={email}
placeholder="[email protected]"
onChange={(e) => setEmail(e.target.value)}
onChange={(e) => {setEmail(e.target.value); e.target.setCustomValidity('');}}
pattern="^[a-zA-Z0-9._%\+\-]+@[a-zA-Z0-9._%\+\-]+\.[a-z]{2,}$"
onInvalid={(e) => e.target.setCustomValidity('الرجاء إدخال بريد إليكتروني صحيح')}
required={true}
/>
<TextInput
Expand Down Expand Up @@ -140,7 +148,9 @@ export default function SignUp() {
name="phone"
value={phone}
placeholder="أكتب رقم هاتفك"
onChange={(e) => setPhone(e.target.value)}
onChange={(e) => {setPhone(e.target.value); e.target.setCustomValidity('');}}
pattern="^01[0-9]{9}$"
onInvalid={(e) => e.target.setCustomValidity('الرجاء إدخال رقم هاتف صحيح')}
required={true}
/>
<RadioInput
Expand Down

0 comments on commit add3758

Please sign in to comment.