import logo from './logo.svg';
import { useState } from 'react';
import './App.css';
function Main(){
const validNumber = [1,3,7,1,3,7,1,3,5];
const [businessNumArray, setBusinessNumArray] = useState([]);
const [tempArray, setTempArray] = useState([]);
//const [sum, setSum] = useState(null);
return (
<div>
<form onSubmit={event=>{
event.preventDefault();
const businessNum = event.target.businessNum.value;
for(let i=0; i<businessNum.length; i++){
setBusinessNumArray(businessNumArray.push(businessNum[i]));
}
let sum = 0;
for(let i=0; i<businessNumArray.length-1; i++){
setTempArray(tempArray.push(validNumber[i] * Number(businessNumArray[i])));
sum += tempArray[i];
}
let last = Math.floor((validNumber[8] * businessNumArray[8]) / 10);
let aa = (sum + last) % 10;
aa = 10 - aa;
if(aa==2){
alert("ok")
} else{
alert("No")
}
// console.log(sum)
// console.log(last)
// console.log(aa)
//console.log(aa)
}}>
<input name='businessNum' placeholder='사업자번호'></input>
<input type='submit' placeholder='유효성검사'></input>
</form>
<div></div>
</div>
)
}
function App() {
return (
<div>
<Main></Main>
</div>
);
}
export default App;
반응형
'FRAME WORK > REACT' 카테고리의 다른 글
React ) state (0) | 2024.09.23 |
---|---|
React ) 컴퍼넌트 (0) | 2024.09.20 |
React ) 수정하기 기초 (1) | 2024.09.20 |
React ) 리액트 설치 (0) | 2024.09.20 |