6
6
View , TouchableOpacity , TextInput , Button , Keyboard
7
7
} from 'react-native' ;
8
8
import { StackNavigator } from 'react-navigation' ;
9
+
10
+
9
11
export default class login extends Component {
10
12
static navigationOptions = ( { navigation} ) => ( {
11
13
title : 'Login' ,
@@ -27,9 +29,26 @@ export default class login extends Component {
27
29
28
30
login = ( ) => {
29
31
const { userEmail, userPassword} = this . state ;
30
- //here we will send our data to server with fetch
32
+ let reg = / ^ \w + ( [ \. - ] ? \w + ) * @ \w + ( [ \. - ] ? \w + ) * ( \. \w { 2 , 3 } ) + $ / ;
33
+ if ( userEmail == "" ) {
34
+ //alert("Please enter Email address");
35
+ this . setState ( { email :'Please enter Email address' } )
36
+
37
+ }
38
+
39
+ else if ( reg . test ( userEmail ) === false )
40
+ {
41
+ //alert("Email is Not Correct");
42
+ this . setState ( { email :'Email is Not Correct' } )
43
+ return false ;
44
+ }
45
+
46
+ else if ( userPassword == "" ) {
47
+ this . setState ( { email :'Please enter password' } )
48
+ }
49
+ else {
31
50
32
- fetch ( 'http ://hardeepcoder .com/react/login.php' , {
51
+ fetch ( 'https ://hardeepwork.000webhostapp .com/react/login.php' , {
33
52
method :'post' ,
34
53
header :{
35
54
'Accept' : 'application/json' ,
@@ -55,6 +74,7 @@ export default class login extends Component {
55
74
. catch ( ( error ) => {
56
75
console . error ( error ) ;
57
76
} ) ;
77
+ }
58
78
59
79
60
80
Keyboard . dismiss ( ) ;
@@ -63,6 +83,7 @@ export default class login extends Component {
63
83
render ( ) {
64
84
return (
65
85
< View style = { styles . container } >
86
+ < Text style = { { padding :10 , margin :10 , color :'red' } } > { this . state . email } </ Text >
66
87
67
88
< TextInput
68
89
placeholder = "Enter Email"
@@ -74,8 +95,10 @@ export default class login extends Component {
74
95
placeholder = "Enter Password"
75
96
style = { { width :200 , margin :10 } }
76
97
onChangeText = { userPassword => this . setState ( { userPassword} ) }
98
+
77
99
/>
78
100
101
+
79
102
< TouchableOpacity
80
103
onPress = { this . login }
81
104
style = { { width :200 , padding :10 , backgroundColor :'magenta' , alignItems :'center' } } >
0 commit comments