0

I've got the following code:

 <TextInput placeholder={"PID"}  keyboardType = 'numeric'  editable = {true}    maxLength = {10} value={this.state.text}  onChangeText={(text) => this.setState({text})} />   
 <Button title='NEXT' onPress= {() => navigate('service', { text: this.state.text})}> </Button>

And I want to validate the input field like this: On a press of the button go to the service page if the length of input is equal to 10. Else show an alert message.

How can I do this?

2 Answers 2

2
manage = () => {
    if (this.state.text.length === 10) {
        navigate('service', { text: this.state.text})})
    } else {
        alert('Your PID must be exactly 10 characters!')
    }
}

render() {
    return (<Button onPress={this.manage} ... />)
}
Sign up to request clarification or add additional context in comments.

1 Comment

It's @sod.heretic's answer, I just helped with the formatting. :)
0

Dear :) You need to use a routing package, like react-navigation or react-native-router-flux (I like the later), define your pages with it, and use a simple if else statement in the onPress function...

Each of the routing packages provide a simple call for programmatic navigation.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.