如何在MUI Textfield中实现文本蒙版

发布于 2025-01-25 07:02:59 字数 666 浏览 3 评论 0原文

因此,我想以价格和信用卡编号为我的MUI Textfields实施口罩,但如何使用。例如,我希望Texfield的价格从“ $”开始,并以“ - ”分开卡号。我已经尝试了此主题,但是它行不通。这是我的Textfields之一:

<TextField
  required
  className="form__input"
  id="price"
  name="price"
  value={formData.price}
  label="Ticket Price"
  variant="outlined"
  type="number"
  onChange={(event) => eventHandleChange(event)}
  error={!/(^$)|(^[+]?\d+([.]\d+)?$)/.test(formData.price)}
  helperText={
    !/(^$)|(^[+]?\d+([.]\d+)?$)/.test(formData.price) &&
    validations.positiveNumbersOnly
  }
/>

So I want to implement a mask to my mui Textfields for price and credit card number, but idk how. For example I want the price texfield to start with "$", and the card number to be separated with "-". I've tried the things from this topic , but it doesn't work. Here is one of my textfields:

<TextField
  required
  className="form__input"
  id="price"
  name="price"
  value={formData.price}
  label="Ticket Price"
  variant="outlined"
  type="number"
  onChange={(event) => eventHandleChange(event)}
  error={!/(^$)|(^[+]?\d+([.]\d+)?$)/.test(formData.price)}
  helperText={
    !/(^$)|(^[+]?\d+([.]\d+)?$)/.test(formData.price) &&
    validations.positiveNumbersOnly
  }
/>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文