我使用 react-native 创建了一个登录表单,我想验证每个字段,但我不知道该怎么做。我对本机反应很陌生,所以我想向任何人寻求帮助。表单验证应在以下情况下显示错误:
示例图像验证:
这是我的代码:
import React from 'react';
import { StyleSheet, Text, View, Image, TextInput, Dimensions, ScrollView,
CheckBox, TouchableOpacity } from 'react-native';
import logo from './image/Logo.png'
const { width: WIDTH } = Dimensions.get('window')
export default class App extends React.Component {
constructor(){
super();
this.state={
check:false,
email: '',
};
this.validates = this.validates.bind(this);
}
CheckBoxText(){
this.setState({
check:!this.state.check,
})
}
validates = () => {
let text = this.state.email;
let emailError = this.state.emails;
let reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/ ; …Run Code Online (Sandbox Code Playgroud) react-native ×1