BFE.dev
React 代码题10. phone number input

10. phone number input

React Stripe LeetCode
分享给更多人

  -通过 / -执行

Create a PhoneNumberInput component.

  1. only accepts numerical digits
  2. format the number automatically as (123)456-7890 by
  • adding the parenthesis when the 4th digit is entered
  • also adding - before 7th digit

You can use the default text input without any styling.

Follow-up

What if user removes some digits in the middle, does caret jumps to the end in your approach?

caret position is not covered in our tests.

上一个下一个

普通解法但是bugfree胜于奇技淫巧但是各种bug。

请求解答AI视频(1)讨论(128)

Try it out

Console