Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolved the issue of validating telephone number #1469

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions packages/fuselage/src/components/TelephoneInput/TelephoneInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ComponentProps, ReactNode, Ref } from 'react';
import { forwardRef } from 'react';
import { forwardRef, useState } from 'react';

import { InputBox } from '../InputBox';

Expand All @@ -16,5 +16,22 @@ export const TelephoneInput = forwardRef(function TelephoneInput(
props: TelephoneInputProps,
ref: Ref<HTMLInputElement>,
) {
return <InputBox type='tel' ref={ref} {...props} />;
const [value, setValue] = useState('');

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const telephonicValue = event.target.value;
if (/^[0-9()+]*$/.test(telephonicValue)) {
setValue(telephonicValue);
}
};

return (
<InputBox
type='tel'
ref={ref}
value={value}
onChange={handleChange}
{...props}
/>
);
});