SHARE
TWEET

Untitled

a guest Jun 26th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. validateForm(e) {
  2.     this.setState({disableButton: true}, () => {
  3.  
  4.     let name = this.state.name
  5.     let email = this.state.email
  6.     let password = this.state.password
  7.     let cpassword = this.state.cpassword
  8.  
  9.  
  10.     let emailRegex = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
  11.     const nameError = name.length < 3;
  12.     const emailError = !emailRegex.test(email);
  13.     const passwordError = password.length < 2;
  14.     const cpasswordError = cpassword !== password;
  15.  
  16.     if ([nameError, emailError, passwordError, cpasswordError].every((v) => {return v == false})) {
  17.         console.log('valid: ', [nameError, emailError, passwordError, cpasswordError])
  18.         this.registerUser(name, email, password, () => {this.setState({disableButton: false})
  19. });
  20.     } else {
  21.         this.setState({registered: false})
  22.         console.log("invalid: ", [nameError, emailError, passwordError, cpasswordError])
  23.     }
  24.     this.setState({nameError, emailError, passwordError, cpasswordError})
  25.  
  26.  
  27.  
  28.     this.setState({disableButton: false})
  29.  
  30.     })
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top