-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathApp.js
74 lines (72 loc) · 1.77 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import React from "react";
import { StyleSheet, Text, TextInput, View, Alert, Button } from "react-native";
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
email: "",
password: ""
};
}
validate = () => {
var emailError = false;
var passwordError = false;
if (!this.state.email.includes("@")) {
emailError = true;
Alert.alert("Alert", "Not a valid email.", [
{ text: "OK", onPress: () => {} }
]);
return;
}
if (this.state.password.length < 6) {
passwordError = true;
Alert.alert("Alert", "Not a valid password.", [
{ text: "OK", onPress: () => {} }
]);
return;
}
if (!(emailError || passwordError)) {
Alert.alert(
"Alert",
`Email: ${this.state.email}, Password: ${this.state.password}`,
[{ text: "OK", onPress: () => {} }]
);
}
};
render() {
return (
<View style={styles.container}>
<TextInput
style={{
height: 60,
width: 200,
paddingTop: 20,
paddingBottom: 5
}}
placeholder="Enter you email"
onChangeText={email => this.setState({ email })}
/>
<TextInput
style={{
height: 60,
width: 200,
paddingTop: 20,
paddingBottom: 5
}}
secureTextEntry
placeholder="Enter you Password"
onChangeText={password => this.setState({ password })}
/>
<Button title="Submit" onPress={this.validate} />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
paddingTop: 50
}
});