小编cha*_*mar的帖子

我如何编写正则表达式以仅接受 antd 输入的数字

我只需要在我的 antd 输入字段中输入数字。但它接受数字和字母。因为我的需求逻辑工作正常,除了字母表。那么我怎么能写一个只接受数字的正则表达式呢?

import React from 'react'
import * as AntD from "antd";
import { Input, Tooltip } from 'antd';
const { Row, Col } = AntD;

function creditCardFormatter(value) {
  var v = value.replace(/\s+/g, '').replace(/[^0-9]/gi, '')
  var matches = v.match(/\d{4,16}/g);
  var match = matches && matches[0] || '';
  var parts = [];
  for (let i = 0, len = match.length; i < len; i += 4) {
    parts.push(match.substring(i, i + 4));
    console.log(parts)
    console.log(match)}
  if (parts.length){
    console.log(parts.length)
    return parts.join(' ');
  } …
Run Code Online (Sandbox Code Playgroud)

regex reactjs antd

5
推荐指数
2
解决办法
9089
查看次数

标签 统计

antd ×1

reactjs ×1

regex ×1