This is a simple React-Native form InputBox with three main feature: 1- Floating Label, 2- Form Validation with custom error message, 3- Left - Right icon in InputBox
npm install validate-form-in-expo-styleReact-Native Expo Form Validation Component Library with Floating Label!
===================

š Hey! I'm Radhakishan Jangid š. More about me Here ā©.
ā¹ļø validate-form-in-expo-style is a Simple form validation component with floating label for React-Native inspired by react-native-form-validator. You can add floating label with this library and can validate form. I created this package for my personal use you can use it in yours too.
----------
My bad, that I don't have Mac or IPhone, so this library is tested only in android. Do check it in Mac and let me know if any problem occurs.
----------
š Table of Contents
--
- Install
- Supported Types
- Default Validation Rules
- Example
- How to use
- Props
- Methods
- Contributing
- License
š„ Install
--
``sh`
$ npm install validate-form-in-expo-style `
orsh`
$ yarn add react-native-stylish-accordion
Now we need to install react-native-reanimated and react-lifecycles-compat.
If you are using Expo, to ensure that you get the compatible versions of the libraries, run:
``
expo install react-native-reanimated react-native-gesture-handler react-lifecycles-compat
If you are not using Expo, run the following:
``
yarn add react-native-reanimated react-native-gesture-handler react-lifecycles-compat
āļø Supported types:-
----------
- TextInput
š Default Validation Rules are:-
----------
- matchRegexp
- isEmail
- isEmpty
- required
- trim
- isNumber
- isFloat
- isPositive
- minNumber
- maxNumber
- minFloat
- maxFloat
- minStringLength
- maxStringLength
- isString
Some rules that are added in validationName can accept extra parameter for validation, like:
``javascript``
validateNames={['minNumber:1', 'maxNumber:255', 'matchRegexp:^[0-9]$']}
/>
š„ See the full example of form validation in react-native Expo:-
----------

š” How to use:-
----------
``javascript
import React from 'react';
import { StyleSheet, View, Text, Dimensions, TouchableOpacity, Image, ScrollView } from 'react-native';
import { Form, InputText } from 'validate-form-in-expo-style';
import { FontAwesome, Feather } from "@expo/vector-icons";
class App extends React.Component {
state = {
first_name: "",
number: "",
last_name: "",
email: '',
user: { password: "", repeatPassword: "" },
}
componentDidMount() {
//You can add your own rules
Form.addValidationRule('isValidPassword', (value) => {
let passwordReg = /^(?=.\d)(?=.[a-z])(?=.[A-Z])(?=.[a-zA-Z]).{8,}$/;
if (passwordReg.test(value) === false) {
return false;
}
return true;
});
Form.addValidationRule('isPasswordMatch', (value) => {
if (value !== this.state.user.password) {
return false;
}
return true;
});
}
componentWillUnmount() {
// Remove own rules
Form.removeValidationRule('isPasswordMatch');
Form.removeValidationRule('isValidPassword');
}
handlePassword = (event) => {
const { user } = this.state;
user.password = event.nativeEvent.text;
this.setState({ user });
}
handleRepeatPassword = (event) => {
const { user } = this.state;
user.repeatPassword = event.nativeEvent.text;
this.setState({ user });
}
handleChange = (email) => {
this.setState({ email });
}
handleFirstName = (first_name) => {
this.setState({ first_name });
}
handleLastName = (last_name) => {
this.setState({ last_name });
}
handleNumber = (number) => {
this.setState({ number });
}
submit = () => {
alert("form submit, thank you.")
}
handleSubmit = () => {
this.refs.form.submit();
}
render() {
let Image_Http_URL = { uri: 'https://radhakishan.vpran.in/img/radhakishan-web-3.jpg' };
const { user } = this.state;
return (
);
}
}
export default App;
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
action: {
width: Dimensions.get('window').width,
padding: 20
},
appButtonContainer: {
elevation: 8,
backgroundColor: "#009688",
borderRadius: 10,
paddingVertical: 10,
paddingHorizontal: 12,
marginTop: 10
},
appButtonText: {
fontSize: 18,
color: "#fff",
fontWeight: "bold",
alignSelf: "center",
textTransform: "uppercase"
}
labelStyle: {
fontSize: hp('1.8%'),
color: constants.white,
paddingTop: hp('0.8%'),
opacity: .9,
// top: 20
},
inputStyle: {
color: constants.white,
paddingTop: hp('1%'),
},
inputContainerStyle: {
paddingBottom: hp('1%'),
paddingTop: hp('1.3%'),
borderWidth: 2,
borderBottomWidth: 2,
// borderColor: "#333333",
// borderBottomColor: "#333333",
borderColor: constants.primaryColor,
borderBottomColor: constants.primaryColor,
borderRadius: 15
},
inputIconStyle: {
marginHorizontal: 10,
fontSize: hp('2.3%'),
backgroundColor: "#333333",
borderRadius: 5,
alignSelf: "center",
paddingHorizontal: hp('0.2%'),
paddingVertical: hp('0.1%'),
}
});
``
š Props
----
#### Form Props
| Prop | Required | Type | Default value | Description |
|-----------------|----------|----------|---------------|------------------------------------------------------------------------------------------------------------------------------|
| onSubmit | true | function | | Callback for form that fires when all validations are passed |
| instantValidate | false | bool | true | If true, form will be validated after each field change. If false, form will be validated only after clicking submit button. |
| onError | false | function | | Callback for form that fires when some of validations are not passed. It will return array of elements which not valid. |
| debounceTime | false | number | 0 | Debounce time for validation i.e. your validation will run after debounceTime ms when you stop changing your input |
#### InputText Props
| Prop | Required | Type | Default value | Description |
|-----------------|----------|----------|---------------|----------------------------------------------------------------------------------------|
| name | true | string | | Name of input field |
| label | false | string | | Name of input Floating Label |
| placeholder | false | string | | Placeholder of input before any value |
| validateNames | false | array | | Array of validation. See list of default validation rules in above example. |
| errorMessages | false | array | | Array of error messages. Order of messages should be the same as validateNames prop. |true
| errorStyle | false | object | { container: { top: 0, left: 0, position: 'absolute' }, text: { color: 'red' }, underlineValidColor: 'gray', underlineInvalidColor: 'red' } } | Add your own error styles |
| validatorListener | false | function | | It triggers after each validation. It will return or false |required
| withRequiredValidator | false | bool | | Allow to use validator in any validation trigger, not only form submit |
| leftIcon | false | code, image | | Either include image or add Icon tag code to display left icon see above example |
| invalidIcon | false | code, image | | Either include image or add Icon tag code to display error icon on right side see above example |
| validIcon | false | code, image | | Either include image or add Icon tag code to display success icon on right side see above example |
| secureTextEntry | false | bool | false | If true than show hide icon will get added automatically |
š Methods
----
#### Form Methods
| Name | Params | Return | Descriptipon |
|------------------|--------|--------|----------------------------------------------------|
| resetValidations | | | Reset validation messages for all validated inputs |
| isFormValid | dryRun: bool (default true) | Promise | Get form validation state in a Promise (true if whole form is valid). Run with dryRun = false` to show validation errors on form |
#### InputText Methods
| Name | Params | Return | Descriptipon |
|------------------|--------|--------|----------------------------------------------------|
| getErrorMessage | | | Get error validation message |
| validate | value: any, includeRequired: bool | | Run validation for current component |
| isValid | | bool | Return current validation state |
| makeInvalid | | | Set invalid validation state |
| makeValid | | | Set valid validation state |
š¼ Contributing
----
This component covers all my needs, but feel free to contribute.
š License
---
MIT Ā© Radhakishan Jangid