I am trying to validate a users email, by checking it against an expression. But the result i am getting is invalid for all the entries.
UPDATED CODE
Looks like a syntax error. You've got a nested function called validate
directly inside the definition for go
.
As a general rule I would suggest to keep your indentation and curly-brackets consistent so these sort of errors are detectable at a glance-- when the brackets don't line up there's a problem.
Then, there's a few things you might do to get this code working:
validate (email)
line along with its accompanying close
bracketgo
Something like:
this.state = {
email :'',
validated : false,
}
And...
go = () => {
if (this.state.email.test(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/)==0) {
this.setState({ validated : true });
} else {
this.setState({ validated : false });
}
}