How to validate all the fields from the front end I have 4 fields here i have written a function on blur how can i proceed to this
import React, { Component } from 'react'
class Signup extends Component {
constructor(props) {
super(props);
this.state = {
mobileno: '',
email: '',
password: '',
}
}
hanldeValidation(text, type) {
var mobilregex = /^[0-9]/;
if (this.state.mobileno == '' && mobilregex.test(text) == false) {
this.setState({
errormobile: true
})
}
else if (this.state.email == '' && emailregex.test(text) == false) {
this.setState({
erroremail: true
})
}
}
render() {
return (
<View>
<Content style={{
paddingLeft: 10,
paddingRight: 10,
backgroundColor: 'white'
}}>
<View style={{ paddingTop: 35, backgroundColor: '#ffffff', width: '100%', alignItems: 'center' }}>
{/* Input Fields */}
<Item >
<Input ref="mobileno" placeholder={strings('EnterMobileno')}
value={this.state.mobileno}
onChangeText={(mobileno) => this.setState({ mobileno: mobileno })}
onBlur={(mobileno) => this.hanldeValidation(mobileno, 'mobileno')}
/>
</Item>
{
this.state.errormobile ?
<Text style={{ textAlign: 'center', color: 'red' }}>
{'Enter a valid number'}
</Text>
:
null
}
<Item >
<Input ref="email" placeholder={'Enter Email ( optional )'}
value={this.state.email}
onChangeText={(email) => this.setState({ email: email })}
/>
</Item>
<Item >
<Input ref="password" placeholder={'Enter password'}
value={this.state.password}
onChangeText={(password) => this.setState({ password: password })}
/>
</Item>
{/* Signup Button */}
<Button block rounded
style={styles.loginButtonStyle}
onPress={() => this.props.createUser(this.state)}
>
Signup
</Button>
</View>
</Content>
</View >
)
}
}
const mapStateToProps = (state) => {
}
const mapDispatchToProps = (dispatch) => {
}
export default (SignupScreen)