Skip to content

Commit

Permalink
Merge pull request #298 from readyvery/test
Browse files Browse the repository at this point in the history
Feat: 전화번호 입력 시 하이픈 추가
  • Loading branch information
marinesnow34 authored Apr 9, 2024
2 parents 1994873 + c78bcff commit 489cc36
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/components/Authentication/UserInputNumber.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,19 @@ const UserInputNumber = () => {
};

const handlePhoneChange = (event) => {
setPhonenumber(event.target.value);
const HyphenNumber = event.target.value.replace(/[^0-9]/g, "");
setPhonenumber(HyphenNumber);
};
const displayFormattedPhoneNumber = (numbers) => {
if (numbers.length <= 3) {
return numbers;
} else if (numbers.length <= 7) {
return `${numbers.slice(0, 3)}-${numbers.slice(3)}`;
} else {
return `${numbers.slice(0, 3)}-${numbers.slice(3, 7)}-${numbers.slice(
7
)}`;
}
};
// 번호 인증 성공 여부 확인
const handleAuthSuccess = (success) => {
Expand All @@ -55,9 +67,12 @@ const UserInputNumber = () => {
<div className="user-input-phone-number-wrapper">
<input
type="tel"
inputmode="numeric"
pattern="[0-9]*"
placeholder="전화번호"
value={Phonenumber}
value={displayFormattedPhoneNumber(Phonenumber)}
onChange={handlePhoneChange}
maxLength="13"
className="user-input-phone-number-input"
/>
<button
Expand Down

0 comments on commit 489cc36

Please sign in to comment.