Skip to content

Commit 0a6e9b8

Browse files
committed
custom validation
1 parent e82ded9 commit 0a6e9b8

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

pages/home.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ export default class home extends Component{
66
static navigationOptions= ({navigation}) =>({
77
title: 'Welcome',
88
});
9-
9+
1010
render(){
1111
const { navigate } = this.props.navigation;
1212
return(
1313
<View style={styles.container}>
1414
<Text style={styles.pageName}>User Manager</Text>
15+
16+
1517

1618
<TouchableOpacity
1719
onPress={() => navigate('Login')}

pages/login.js

+25-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
View,TouchableOpacity,TextInput,Button,Keyboard
77
} from 'react-native';
88
import { StackNavigator } from 'react-navigation';
9+
10+
911
export default class login extends Component {
1012
static navigationOptions= ({navigation}) =>({
1113
title: 'Login',
@@ -27,9 +29,26 @@ export default class login extends Component {
2729

2830
login = () =>{
2931
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{
3150

32-
fetch('http://hardeepcoder.com/react/login.php',{
51+
fetch('https://hardeepwork.000webhostapp.com/react/login.php',{
3352
method:'post',
3453
header:{
3554
'Accept': 'application/json',
@@ -55,6 +74,7 @@ export default class login extends Component {
5574
.catch((error)=>{
5675
console.error(error);
5776
});
77+
}
5878

5979

6080
Keyboard.dismiss();
@@ -63,6 +83,7 @@ export default class login extends Component {
6383
render() {
6484
return (
6585
<View style={styles.container}>
86+
<Text style={{padding:10,margin:10,color:'red'}}>{this.state.email}</Text>
6687

6788
<TextInput
6889
placeholder="Enter Email"
@@ -74,8 +95,10 @@ export default class login extends Component {
7495
placeholder="Enter Password"
7596
style={{width:200, margin:10}}
7697
onChangeText={userPassword => this.setState({userPassword})}
98+
7799
/>
78100

101+
79102
<TouchableOpacity
80103
onPress={this.login}
81104
style={{width:200,padding:10,backgroundColor:'magenta',alignItems:'center'}}>

pages/profile.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ export default class home extends Component{
55
static navigationOptions= ({navigation}) =>({
66
title: 'Welcome',
77
});
8-
8+
99
render(){
1010
const { navigate } = this.props.navigation;
1111
return(
1212
<View style={styles.container}>
1313

1414
<Text style={styles.pageName}>profile</Text>
1515

16+
1617
</View>
1718
);
1819
}

pages/register.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
Text,
66
View,Button,TextInput,TouchableOpacity
77
} from 'react-native';
8-
import { StackNavigator } from 'react-navigation';
8+
9+
910
export default class register extends Component {
1011
static navigationOptions= ({navigation}) =>({
1112
title: 'Register',
@@ -35,7 +36,7 @@ export default class register extends Component {
3536
const {userPassword} = this.state;
3637

3738

38-
fetch('http://hardeepcoder.com/react/register.php', {
39+
fetch('https://hardeepwork.000webhostapp.com/react/register.php', {
3940
method: 'post',
4041
header:{
4142
'Accept': 'application/json',
@@ -61,7 +62,8 @@ export default class register extends Component {
6162
render() {
6263
return (
6364
<View style={styles.container}>
64-
65+
66+
6567
<TextInput
6668
placeholder="Enter Name"
6769
style={{width:250,margin:10, borderColor:"#333",

0 commit comments

Comments
 (0)