我只需要在我的 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)