Avi*_*ati 17 javascript validation react-native react-native-ios
我试图通过对表达式进行检查来验证用户的电子邮件.但我得到的结果对所有条目都无效.
更新的代码
class dummytest extends Component{
constructor(props){
super(props);
this.state = {
email :'',
validated: false ,
}
};
go = () => {
const reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if (reg.test(this.state.email) === true){
alert( valid);
}
else{
alert();
}
}
render(){
return(
<View style={{alignSelf:'center',marginTop:100}}>
<TextInput autoCapitalize="none" autoCorrect={false} style={{height:20,width:200,backgroundColor:'blue'}} value={this.setState.email}/>
<Button onPress={this.go.bind(this)}>
<Text> GO </Text>
</Button>
</View>
);
}
}
Run Code Online (Sandbox Code Playgroud)
Nee*_*ala 44
好的,我的代码正常工作,下面你可以看看验证每个用户输入的电子邮件.
你的功能部分:
validate = (text) => {
console.log(text);
let reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/ ;
if(reg.test(text) === false)
{
console.log("Email is Not Correct");
this.setState({email:text})
return false;
}
else {
this.setState({email:text})
console.log("Email is Correct");
}
}
Run Code Online (Sandbox Code Playgroud)你的TextInput组件:
<TextInput
placeholder="Email ID"
onChangeText={(text) => this.validate(text)}
value={this.state.email}
/>
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
35161 次 |
| 最近记录: |