Skip to content

Commit bb225bd

Browse files
committed
validation added to signin form
1 parent da05c26 commit bb225bd

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

04_REACT/ecommerce-app/src/pages/Registration.js

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,40 @@ const Registration = () => {
77
const [name, setName] = useState("");
88
const [email, setEmail] = useState("");
99
const [password, setPassword] = useState("");
10-
const [cPasssword, setCPasssword] = useState("");
10+
const [cPasssword, setCPassword] = useState("");
1111

1212
// Error Message
1313
const [errName, setErrName] = useState("");
1414
const [errEmail, setErrEmail] = useState("");
1515
const [errPassword, setErrPassword] = useState("");
16-
const [errCPasssword, setErrCPasssword] = useState("");
16+
const [errCPassword, setErrCPassword] = useState("");
1717

1818
// Handle function
1919
const handleName = (e) =>{
2020
setName(e.target.value)
21+
}
22+
const handleEmail = (e) =>{
23+
setEmail(e.target.value)
24+
}
25+
const handlePassword = (e) =>{
26+
setPassword(e.target.value)
27+
}
28+
const handleCPassword = (e) =>{
29+
setCPassword(e.target.value)
2130
}
2231
const handleRegistration = (e) =>{
2332
e.preventDefault()
2433
if(!name){
25-
setErrName("!Enter your name");
34+
setErrName("Enter your name");
35+
}
36+
if(!email){
37+
setErrEmail("Enter your email")
38+
}
39+
if(!password){
40+
setErrPassword("Password can't be empty")
41+
}
42+
if(!cPasssword){
43+
setErrCPassword("Password is not matching")
2644
}
2745
}
2846

@@ -51,36 +69,64 @@ const Registration = () => {
5169
{
5270
errName && (
5371
<p className='text-red-600 text-xs font-semibold tracking-wide
54-
flex items-center gap-2 -mt-1.5'><span className="italic font-bold">!</span>{errName}</p>
72+
flex items-center gap-2 -mt-1.5'><span className="italic font-bold">
73+
!</span>{errName}</p>
5574
)
5675
}
5776
</div>
5877
<div className='flex flex-col gap-2 '>
5978
<p className='text-sm font-medium'>Email or mobile phone number</p>
60-
<input
79+
<input
80+
onChange={handleEmail}
6181
type="email"
6282
className='w-full lowercase py-1 border border-zinc-400 px-2 text-base
6383
rounded-sm outline-none focus-within:border-[#e77600]
6484
focus-within:shadow-amazonInput duration-200'
6585
/>
86+
{/* Validation */}
87+
{
88+
errEmail && (
89+
<p className='text-red-600 text-xs font-semibold tracking-wide
90+
flex items-center gap-2 -mt-1.5'><span className="italic font-bold">
91+
!</span>{errEmail}</p>
92+
)
93+
}
6694
</div>
6795
<div className='flex flex-col gap-2 '>
6896
<p className='text-sm font-medium'>Password</p>
6997
<input
98+
onChange={handlePassword}
7099
type="password"
71100
className='w-full lowercase py-1 border border-zinc-400 px-2 text-base
72101
rounded-sm outline-none focus-within:border-[#e77600]
73102
focus-within:shadow-amazonInput duration-200'
74103
/>
104+
{/* Validation */}
105+
{
106+
errPassword && (
107+
<p className='text-red-600 text-xs font-semibold tracking-wide
108+
flex items-center gap-2 -mt-1.5'><span className="italic font-bold">
109+
!</span>{errPassword}</p>
110+
)
111+
}
75112
</div>
76113
<div className='flex flex-col gap-2 '>
77114
<p className='text-sm font-medium'>Re-enter Password</p>
78115
<input
116+
onChange={handleCPassword}
79117
type="password"
80118
className='w-full lowercase py-1 border border-zinc-400 px-2 text-base
81119
rounded-sm outline-none focus-within:border-[#e77600]
82120
focus-within:shadow-amazonInput duration-100'
83121
/>
122+
{/* Validation */}
123+
{
124+
errCPassword && (
125+
<p className='text-red-600 text-xs font-semibold tracking-wide
126+
flex items-center gap-2 -mt-1.5'><span className="italic font-bold">
127+
!</span>{errCPassword}</p>
128+
)
129+
}
84130
<p className='text-sm text-gray-600'>
85131
Password must be atleast 6 charcters
86132
</p>

0 commit comments

Comments
 (0)