Skip to content

Commit dc34645

Browse files
authored
Merge pull request #170 from Nilay-Shahane/main-616
Changed the flow and css by a bit , replaced text to password
2 parents a2bed2c + 39f17ae commit dc34645

File tree

1 file changed

+82
-31
lines changed

1 file changed

+82
-31
lines changed

Credit-Card-Validator/src/App.jsx

Lines changed: 82 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,87 @@
1-
// App.js
1+
import React, { useState } from "react";
2+
import validator from "validator";
23

3-
import React, { useState } from "react";
4-
import validator from 'validator'
4+
const App = () => {
5+
const [errorMessage, setErrorMessage] = useState("");
6+
const [flag, setFlag] = useState(false);
7+
const [credit, setCredit] = useState("");
58

6-
const App = () => {
9+
const validateCreditCard = (value) => {
10+
if (validator.isCreditCard(value)) {
11+
setErrorMessage(" Valid Credit Card Number");
12+
setFlag(true);
13+
}
14+
else if(value===''){
15+
setErrorMessage("");
16+
}
17+
else {
18+
setErrorMessage(" Enter a valid Credit Card Number!");
19+
setFlag(false);
20+
}
21+
};
722

8-
const [errorMessage, setErrorMessage] = useState('')
9-
10-
const validateCreditCard = (value) => {
11-
12-
if (validator.isCreditCard(value)) {
13-
setErrorMessage('Valid CreditCard Number')
14-
} else {
15-
setErrorMessage('Enter valid CreditCard Number!')
16-
}
17-
}
23+
return (
24+
<div
25+
style={{
26+
display: "flex",
27+
flexDirection: "column",
28+
alignItems: "center",
29+
fontFamily: "Arial, sans-serif",
30+
padding: "40px",
31+
backgroundColor: "#f9f9f9",
32+
height: "100vh",
33+
}}
34+
>
35+
<div
36+
style={{
37+
background: "#101b30",
38+
padding: "30px 40px",
39+
borderRadius: "10px",
40+
boxShadow: "0 4px 10px rgba(0,0,0,0.1)",
41+
maxWidth: "400px",
42+
width: "100%",
43+
}}
44+
>
45+
<h2 style={{ color: "#fff", marginBottom: "20px" }}>
46+
Credit Card Validator
47+
</h2>
1848

19-
return (
20-
<div style={{
21-
marginLeft: '200px',
22-
}}>
23-
<pre>
24-
<h2>Validating CreditCard in ReactJS</h2>
25-
<span>Enter CreditCard: </span><input type="text"
26-
onChange={(e) => validateCreditCard(e.target.value)}></input> <br />
27-
<span style={{
28-
fontWeight: 'bold',
29-
color: 'red',
30-
}}>{errorMessage}</span>
31-
</pre>
32-
</div>
33-
);
34-
}
49+
<label style={{ marginBottom: "10px", display: "block", color: "#aaa" }}>
50+
Enter Credit Card Number:
51+
</label>
3552

36-
export default App
53+
<input
54+
type="password"
55+
value={credit}
56+
onChange={(e) => {
57+
const newValue = e.target.value;
58+
setCredit(newValue);
59+
validateCreditCard(newValue);
60+
}}
61+
placeholder="•••• •••• •••• ••••"
62+
style={{
63+
width: "100%",
64+
padding: "10px",
65+
fontSize: "16px",
66+
border: "1px solid #ccc",
67+
borderRadius: "6px",
68+
outline: "none",
69+
marginBottom: "15px",
70+
}}
71+
/>
72+
73+
<div
74+
style={{
75+
fontWeight: "600",
76+
color: flag ? "#44ed23" : "red",
77+
minHeight: "24px",
78+
}}
79+
>
80+
{errorMessage}
81+
</div>
82+
</div>
83+
</div>
84+
);
85+
};
86+
87+
export default App;

0 commit comments

Comments
 (0)