import { BaseProps , validateDecimal , validateInteger } from '@celo/base/lib/inputValidation' ; import { getDisplayPhoneNumber } from './phoneNumbers' ; export { BaseProps , validateDecimal , validateInteger , ValidatorKind , } from '@celo/base/lib/inputValidation' ; export function validatePhone ( input , countryCallingCode ? ) { input = input . replace ( /[^0-9()\- ]/g , '' ) ; if ( ! countryCallingCode ) { return input ; } const displayNumber = getDisplayPhoneNumber ( input , countryCallingCode ) ; if ( ! displayNumber ) { return input ; } return displayNumber ; } export function validateInput ( input , props ) { if ( ! props . validator && ! props . customValidator ) { return input ; } switch ( props . validator ) { case 'decimal' : return validateDecimal ( input , props . decimalSeparator ) ; case 'integer' : return validateInteger ( input ) ; case 'phone' : return validatePhone ( input , props . countryCallingCode ) ; case 'custom' : { if ( props . customValidator ) { return props . customValidator ( input ) ; } } } throw new Error ( 'Unhandled input validator' ) ; }