@@ -25,6 +25,8 @@ export interface BankFormData {
2525}
2626
2727export interface RampBankFormParams {
28+ /** ISO country code for region-specific validation */
29+ countryCode : string
2830 onSubmit : ( formData : BankFormData ) => Promise < void >
2931 /**
3032 * Callback invoked when the user navigates away from the scene.
@@ -42,7 +44,7 @@ interface ValidationResult {
4244
4345export const RampBankFormScene : React . FC < Props > = props => {
4446 const { navigation, route } = props
45- const { onSubmit, onCancel } = route . params
47+ const { countryCode , onSubmit, onCancel } = route . params
4648
4749 const theme = useTheme ( )
4850 const styles = getStyles ( theme )
@@ -71,12 +73,12 @@ export const RampBankFormScene: React.FC<Props> = props => {
7173 const routingNumberRef = React . useRef < TextInput > ( null )
7274
7375 const handleAccountNumberBlur = useHandler ( ( ) => {
74- const result = validateAccountNumber ( accountNumber )
76+ const result = validateAccountNumber ( accountNumber , countryCode )
7577 setFieldErrors ( prev => ( { ...prev , accountNumber : result . errorMessage } ) )
7678 } )
7779
7880 const handleRoutingNumberBlur = useHandler ( ( ) => {
79- const result = validateRoutingNumber ( routingNumber )
81+ const result = validateRoutingNumber ( routingNumber , countryCode )
8082 setFieldErrors ( prev => ( { ...prev , routingNumber : result . errorMessage } ) )
8183 } )
8284
@@ -100,8 +102,14 @@ export const RampBankFormScene: React.FC<Props> = props => {
100102 ownerLastName . trim ( ) !== ''
101103
102104 // Use the same validation functions for form validity
103- const accountValid = validateAccountNumber ( accountNumber ) . isValid
104- const routingValid = validateRoutingNumber ( routingNumber ) . isValid
105+ const accountValid = validateAccountNumber (
106+ accountNumber ,
107+ countryCode
108+ ) . isValid
109+ const routingValid = validateRoutingNumber (
110+ routingNumber ,
111+ countryCode
112+ ) . isValid
105113
106114 const hasNoFieldErrors =
107115 fieldErrors . accountNumber === '' && fieldErrors . routingNumber === ''
@@ -110,6 +118,7 @@ export const RampBankFormScene: React.FC<Props> = props => {
110118 } , [
111119 bankName ,
112120 accountNumber ,
121+ countryCode ,
113122 routingNumber ,
114123 accountName ,
115124 ownerFirstName ,
@@ -190,14 +199,15 @@ export const RampBankFormScene: React.FC<Props> = props => {
190199 onSubmitEditing = { ( ) => accountNumberRef . current ?. focus ( ) }
191200 />
192201
202+ { /* TODO: Adjust maxLength for other countries when internationalized */ }
193203 < FilledTextInput
194204 ref = { accountNumberRef }
195205 value = { accountNumber }
196206 onChangeText = { handleAccountNumberChange }
197207 placeholder = { lstrings . ramp_account_number_placeholder }
198208 keyboardType = "number-pad"
199209 returnKeyType = "next"
200- maxLength = { 17 }
210+ maxLength = { countryCode === 'US' ? 17 : undefined }
201211 error = { fieldErrors . accountNumber }
202212 aroundRem = { 0.5 }
203213 onBlur = { handleAccountNumberBlur }
@@ -211,7 +221,7 @@ export const RampBankFormScene: React.FC<Props> = props => {
211221 placeholder = { lstrings . ramp_routing_number_placeholder }
212222 keyboardType = "number-pad"
213223 returnKeyType = "done"
214- maxLength = { 9 }
224+ maxLength = { countryCode === 'US' ? 9 : undefined }
215225 error = { fieldErrors . routingNumber }
216226 aroundRem = { 0.5 }
217227 onBlur = { handleRoutingNumberBlur }
@@ -240,33 +250,50 @@ const getStyles = cacheStyles((theme: Theme) => ({
240250} ) )
241251
242252// Single source of truth for field validation
243- const validateAccountNumber = ( value : string ) : ValidationResult => {
253+ // TODO: Extend validation for other countries when the form is internationalized
254+ const validateAccountNumber = (
255+ value : string ,
256+ countryCode : string
257+ ) : ValidationResult => {
244258 const trimmed = value . trim ( )
245259 if ( trimmed === '' ) {
246260 return { isValid : false , errorMessage : '' }
247261 }
248- if ( trimmed . length < 8 ) {
249- return {
250- isValid : false ,
251- errorMessage : sprintf (
252- lstrings . ramp_account_number_error_min_length_1s ,
253- '8'
254- )
262+
263+ // US bank account numbers typically range from 4-17 digits
264+ if ( countryCode === 'US' ) {
265+ if ( trimmed . length < 4 ) {
266+ return {
267+ isValid : false ,
268+ errorMessage : sprintf (
269+ lstrings . ramp_account_number_error_min_length_1s ,
270+ '4'
271+ )
272+ }
255273 }
256274 }
275+
257276 return { isValid : true , errorMessage : '' }
258277}
259278
260- const validateRoutingNumber = ( value : string ) : ValidationResult => {
279+ const validateRoutingNumber = (
280+ value : string ,
281+ countryCode : string
282+ ) : ValidationResult => {
261283 const trimmed = value . trim ( )
262284 if ( trimmed === '' ) {
263285 return { isValid : false , errorMessage : '' }
264286 }
265- if ( trimmed . length !== 9 ) {
266- return {
267- isValid : false ,
268- errorMessage : sprintf ( lstrings . ramp_routing_number_error_length_1s , '9' )
287+
288+ // US ABA routing numbers are exactly 9 digits
289+ if ( countryCode === 'US' ) {
290+ if ( trimmed . length !== 9 ) {
291+ return {
292+ isValid : false ,
293+ errorMessage : sprintf ( lstrings . ramp_routing_number_error_length_1s , '9' )
294+ }
269295 }
270296 }
297+
271298 return { isValid : true , errorMessage : '' }
272299}
0 commit comments