UNPKG

@coreui/react-pro

Version:

UI Components Library for React.js

24 lines (21 loc) 495 B
export const isValidInput = (inputValue: string, type: 'number' | 'text'): boolean => { if (inputValue.length !== 1) return false switch (type) { case 'number': { return /^\d$/.test(inputValue) } default: { return /^.$/.test(inputValue) } } } export const extractValidChars = (text: string, type: 'number' | 'text'): string => { switch (type) { case 'number': { return text.replaceAll(/\D/g, '') } default: { return text } } }