react-native-fn-forms
v1.2.4
Published
π Smart form validation library for React Native with built-in validators, multi-country phone formatting (14+ countries), icon support, field matching, auto-save, OTP verification. Real-time validation, TypeScript support, accessibility-first, cross-pla
Maintainers
Readme
React Native FN Forms
π The smartest form validation library for React Native π
React Native FN Forms is an intelligent form validation library with built-in field-specific validators for email, phone numbers, names, credit cards, OTP verification, and more. Perfect for React Native apps that need smart, real-time form validation with seamless OTP verification flows.
π― Why Choose React Native FN Forms?
- β 10+ Built-in Validators - Email, phone, credit card, names, addresses, etc.
- β OTP Verification - Complete OTP input component with SMS auto-fill
- β Icon Support - Left/right icons with interactive features (password toggle, clear buttons)
- β Smart Auto-formatting - Phone numbers, credit cards format automatically
- β Real-time Validation - Instant feedback with customizable debouncing
- β TypeScript First - Full type safety and IntelliSense support
- β Accessibility Ready - Screen reader support and proper ARIA labels
- β Cross-platform - iOS, Android, and React Native Web
- β Zero Native Dependencies - Pure JavaScript, easy installation
- β Performance Optimized - Minimal re-renders, efficient validation
β¨ Features
- π§ Smart Field Validation - Built-in validators for common field types (name, email, phone, etc.)
- π OTP Verification - Complete OTP component with SMS auto-fill (iOS/Android)
- π Multi-Country Phone Formatting - Auto-format phone numbers for 14+ countries (US, UK, India, etc.)
- π¨ Icon Support - Left/right icons with interactive handlers (password toggle, clear button, etc.)
- β‘ Real-time Validation - Debounced validation with customizable timing
- π― React Native Optimized - Platform-specific input props and keyboard handling
- π± Cross-platform - Works on iOS, Android, and React Native Web
- π§ TypeScript Support - Full type safety and IntelliSense
- βΏ Accessibility First - Built-in accessibility features and screen reader support
- π¨ Customizable - Flexible styling and custom validation rules
- π¦ Pure JavaScript - No native dependencies, easy installation
π Installation
npm install react-native-fn-forms
# or
yarn add react-native-fn-formsπ Documentation
API Documentation
- π― useSmartForm Hook - Main form management hook
- π¦ SmartFormField Component - Pre-built form field component
- π SmartOTPField Component - OTP verification component
Guides
- π Field Types Guide - All 14 field types with examples
- β Validation Guide - Advanced validation patterns
- π¨ Styling Guide - Customization and theming
- π OTP Guide - Complete OTP implementation guide
- π Multi-Country Phone Formatting - International phone number formatting
Examples
- π Login Form - Complete login form example
- π Signup Form - Registration form with validation
- π³ Payment Form - Credit card payment form
- β Confirmation Fields - Email and password confirmation
- πΎ Auto-save & Draft Recovery - Automatic draft saving
Additional Resources
- πΊοΈ Roadmap - Upcoming features and improvements
- π Changelog - Version history
- π€ Contributing - How to contribute
π Quick Start
import React from 'react';
import { View, Button } from 'react-native';
import { useSmartForm, FormProvider, SmartFormField, SmartOTPField } from 'react-native-fn-forms';
const MyForm = () => {
const form = useSmartForm({
fields: {
name: {
type: 'personName',
required: true,
minLength: 2,
},
email: {
type: 'email',
required: true,
},
phone: {
type: 'phone',
required: false,
},
},
});
const handleSubmit = async () => {
await form.submitForm();
if (form.isValid) {
console.log('Form data:', form.values);
}
};
return (
<FormProvider value={form}>
<View style={{ padding: 20 }}>
<SmartFormField
name="name"
label="Full Name"
placeholder="Enter your name"
/>
<SmartFormField
name="email"
label="Email"
placeholder="Enter your email"
/>
<SmartFormField
name="phone"
label="Phone (Optional)"
placeholder="Enter your phone number"
/>
<Button title="Submit" onPress={handleSubmit} />
</View>
</FormProvider>
);
};οΏ½ OTP Verification Example
import { SmartOTPField } from 'react-native-fn-forms';
const OTPVerification = () => {
const form = useSmartForm({
fields: {
email: { type: 'email', required: true },
otp: { type: 'otp', required: true, length: 6 }
}
});
return (
<FormProvider value={form}>
<View style={{ padding: 20 }}>
<SmartFormField
name="email"
label="Email Address"
placeholder="Enter your email"
/>
<SmartOTPField
name="otp"
label="Verification Code"
length={6}
autoFocus={true}
onComplete={(code) => console.log('OTP Complete:', code)}
/>
<Button title="Verify" onPress={() => form.submitForm()} />
</View>
</FormProvider>
);
};π¨ Fields with Icons
import Icon from 'react-native-vector-icons/MaterialIcons';
const LoginForm = () => {
const [showPassword, setShowPassword] = React.useState(false);
const form = useSmartForm({
fields: {
email: { type: 'email', required: true },
password: { type: 'password', required: true }
}
});
return (
<FormProvider value={form}>
<View style={{ padding: 20 }}>
<SmartFormField
name="email"
label="Email"
placeholder="Enter your email"
leftIcon={<Icon name="email" size={20} color="#666" />}
/>
<SmartFormField
name="password"
label="Password"
placeholder="Enter password"
secureTextEntry={!showPassword}
leftIcon={<Icon name="lock" size={20} color="#666" />}
rightIcon={
<Icon
name={showPassword ? 'visibility' : 'visibility-off'}
size={20}
color="#666"
/>
}
onRightIconPress={() => setShowPassword(!showPassword)}
/>
<Button title="Login" onPress={() => form.submitForm()} />
</View>
</FormProvider>
);
};π Built-in Field Types
| Field Type | Description | Auto-formatting | Validation |
| --------------- | ------------------------------------------------ | ------------------------------ | ------------------------------ |
| personName | Names with letters, spaces, hyphens, apostrophes | β
Capitalizes properly | β
Rejects numbers/symbols |
| businessName | Business names with additional characters | β
Cleans spacing | β
Allows business punctuation |
| email | Email addresses | β
Lowercase formatting | β
Email format validation |
| phone | Phone numbers | β
Format: (123) 456-7890 | β
Valid phone patterns |
| creditCard | Credit card numbers | β
Format: 1234 5678 9012 3456 | β
Luhn algorithm check |
| currency | Monetary values | β
Format: 10.99 | β
Valid currency format |
| username | Usernames | β
Lowercase, clean chars | β
Alphanumeric + _ - |
| streetAddress | Street addresses | β
Title case | β
Address characters |
| url | Web URLs | β
Add https:// if missing | β
Valid URL format |
| password | Passwords | β No formatting | β
Strength requirements |
| otp | OTP codes (4/6/8 digits) | β No formatting | β
Numeric validation |
π₯ Key Features
Auto-save & Draft Recovery
Automatic draft saving with flexible storage adapters:
import AsyncStorage from '@react-native-async-storage/async-storage';
const form = useSmartForm({
fields: {
email: { type: 'email', required: true },
message: { type: 'text', required: true },
},
autoSave: {
enabled: true,
debounce: 1000,
key: 'contact-form-draft',
expirationDays: 7,
storage: {
save: async (key, data) => await AsyncStorage.setItem(key, data),
load: async key => await AsyncStorage.getItem(key),
remove: async key => await AsyncStorage.removeItem(key),
},
},
onDraftFound: draft => {
Alert.alert('Resume?', 'You have unsaved changes', [
{ text: 'Discard', onPress: () => form.clearDraft() },
{ text: 'Resume', onPress: () => form.loadDraft(draft) },
]);
},
});π See auto-save & draft recovery guide β
Field Matching / Confirmation Fields
Built-in support for email and password confirmation:
const form = useSmartForm({
fields: {
email: { type: 'email', required: true },
confirmEmail: {
type: 'email',
required: true,
matchField: 'email',
matchErrorMessage: 'Email addresses must match',
},
password: { type: 'password', required: true, minLength: 8 },
confirmPassword: {
type: 'password',
required: true,
matchField: 'password',
matchErrorMessage: 'Passwords must match',
},
},
});π See confirmation fields example β
Validation Modes
Choose how and when validation happens:
const form = useSmartForm({
validation: {
mode: 'onChange', // Validate as user types
debounce: 300, // Wait 300ms after typing stops
showErrorsOn: 'touched', // Show errors after field interaction
},
fields: {
/* ... */
},
});Custom Validation
Add your own validation logic, including async validation:
username: {
type: 'username',
required: true,
customValidation: async (value) => {
const available = await checkAvailability(value);
return available ? null : 'Username taken';
}
}π See advanced validation patterns β
Custom Styling & Components
Full control over appearance and behavior:
<SmartFormField
name="email"
style={styles.field}
inputStyle={styles.input}
errorStyle={styles.error}
/>π€ Contributing
We welcome contributions! Please see our Contributing Guide for details.
π License
MIT License - see LICENSE file for details.
π Support
- β Star this repo if you find it helpful
- π Report bugs
- π‘ Request features
- π Read the docs
Made with β€οΈ for the React Native community
