首页 > 解决方案 > undefined is not an object (evaluating '_this.state.BankName.trim') in react native

问题描述

I want input field should not be an empty. please help me I am getting this error = undefined is not an object (evaluating '_this.state.BankName.trim')

here is my code

  if (!this.state.BankName.trim()) 
      // if (!/^$|^.*@.*\..*$/.test(this.state.BankName))
      {
        this.setState({ BankNameError: 'Field Should Not Be An Empty' })
        return;
      }
      else {
        Alert.alert("All fields validated")
        return;
      }
    }

  handleBankName = (text) => {
      this.setState({ BankNameError: '' })
      this.setState({ BankName: text })
    }

 <TextInput  maxLength={20} placeholder="Name of Bank*" style={styles.inputStyle} 
         onChangeText={this.handleBankName}  />
         <Text>{this.state.BankNameError}</Text>

标签: react-native

解决方案


推荐阅读