Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Email Validation in React Native using regx

$
0
0

I am using expo with React Native and I am trying to set error message when the email format is not valid

this is my function:

    const emailValidator = (email: any) => {  let reg =  /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;  if (reg.test(email) === false) {    setErrorMassage2(  "Please enter a valid email address" );    return false;  } else {    setErrorMassage2(  "" );  }};

this is my text input:

<TextInput                     style={styles.textInput}                    autoCapitalize="none"                    onChangeText={(e) => setEmail(e.toString())}                    onBlur={(email) => emailValidator(email)} /><Text>                      {errorMassage2}</Text>

but it does not work, anyone have idea?


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>