react check if string is mail

Solutions on MaxInterview for react check if string is mail by the best coders in the world

showing results for - "react check if string is mail"
Felix
19 Feb 2019
1let handleOnChange = ( email ) => {
2
3    // don't remember from where i copied this code, but this works.
4    let re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
5
6    if ( re.test(email) ) {
7        // this is a valid email address
8        // call setState({email: email}) to update the email
9        // or update the data in redux store.
10    }
11    else {
12        // invalid email, maybe show an error to the user.
13    }
14
15}