showing results for - "input type email react js validation"
María Camila
04 Jun 2019
1    class Test extends React.Component {
2        constructor(props){
3           super(props);
4      
5           this.state = {
6               fields: {},
7               errors: {}
8           }
9        }
10    
11        handleValidation(){
12            let fields = this.state.fields;
13            let errors = {};
14            let formIsValid = true;
15
16            //Name
17            if(!fields["name"]){
18               formIsValid = false;
19               errors["name"] = "Cannot be empty";
20            }
21      
22            if(typeof fields["name"] !== "undefined"){
23               if(!fields["name"].match(/^[a-zA-Z]+$/)){
24                  formIsValid = false;
25                  errors["name"] = "Only letters";
26               }        
27            }
28       
29            //Email
30            if(!fields["email"]){
31               formIsValid = false;
32               errors["email"] = "Cannot be empty";
33            }
34      
35            if(typeof fields["email"] !== "undefined"){
36               let lastAtPos = fields["email"].lastIndexOf('@');
37               let lastDotPos = fields["email"].lastIndexOf('.');
38
39               if (!(lastAtPos < lastDotPos && lastAtPos > 0 && fields["email"].indexOf('@@') == -1 && lastDotPos > 2 && (fields["email"].length - lastDotPos) > 2)) {
40                  formIsValid = false;
41                  errors["email"] = "Email is not valid";
42                }
43           }  
44
45           this.setState({errors: errors});
46           return formIsValid;
47       }
48        
49       contactSubmit(e){
50            e.preventDefault();
51
52            if(this.handleValidation()){
53               alert("Form submitted");
54            }else{
55               alert("Form has errors.")
56            }
57      
58        }
59    
60        handleChange(field, e){         
61            let fields = this.state.fields;
62            fields[field] = e.target.value;        
63            this.setState({fields});
64        }
65    
66        render(){
67            return (
68                <div>           
69                   <form name="contactform" className="contactform" onSubmit= {this.contactSubmit.bind(this)}>
70                        <div className="col-md-6">
71                          <fieldset>
72                               <input ref="name" type="text" size="30" placeholder="Name" onChange={this.handleChange.bind(this, "name")} value={this.state.fields["name"]}/>
73                               <span style={{color: "red"}}>{this.state.errors["name"]}</span>
74                              <br/>
75                             <input refs="email" type="text" size="30" placeholder="Email" onChange={this.handleChange.bind(this, "email")} value={this.state.fields["email"]}/>
76                             <span style={{color: "red"}}>{this.state.errors["email"]}</span>
77                             <br/>
78                             <input refs="phone" type="text" size="30" placeholder="Phone" onChange={this.handleChange.bind(this, "phone")} value={this.state.fields["phone"]}/>
79                             <br/>
80                             <input refs="address" type="text" size="30" placeholder="Address" onChange={this.handleChange.bind(this, "address")} value={this.state.fields["address"]}/>
81                             <br/>
82                         </fieldset>
83                      </div>
84          
85                  </form>
86                </div>
87          )
88        }
89    }
90
91    React.render(<Test />, document.getElementById('container'));
92
93
Sofia
20 Aug 2020
1if (/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(email)) {
2
queries leading to this page
regex for email validation in reactjssimple form react email validationreact form email validationgenerate email verification code in react jsreact js onchange email validationemail validation in reactinput type email react text field validationverify email reacthow to check email pattern in reactemail validation check in reactjsemail validation on submit button reactjsreact input email validationemail input validation reactemail validation javascript reactvalider email react email regex validation reactemail and text field validation in react jsvalidation email regex reactvalid email react js functionreact email validation regexemail validation in react nativeemail custom validation reactvalidate email input in react jsreact email validation exampleemail validatition in reactjshow to add email validation in react jsemail form validation reactemail validation react inputhow to validate email in react how to check email validation in react jsemail validation in react jsreact form validation emailhow to validate email using validator in react jsreact js email validationhow to do email validation in react jsemail validation in react js using hooksinput type email react js validationemail input validator reactvalidate email in reactjs class compoenetsvalidation email while typing in react inputvalidate email in reactregex for email validation reactjscheck valid email in reactreact check valid emailreact email validation patternvalidate form email reactvalidate email text reactemail input verify reactreact validate emailemail input validation in react jsemail validation in reactjsemail validation input reactemail and confirm email validation in react jsregex for email validation in react jsemail validation react jsjavascript using email validation form using reactreact email form validationcustom email validation reactjsemail verification in react jsreact validate email input how to valid email in reactjsemail and confirm email validation in react js funreact check for valid emailemail validation react mediuminput email validation reactemail verification react jsemail in react jsemail validation regex in reactemail validation check in react jsinput type email reactemail input validation reactverification email in react jshow to validation email and check existing email in react jshow to add validation in email field reacthow to validate email address in react jsemail validation in react js using functional componentnodejs email validation reactjsvalidate email regex reactjscheck email field reactvalidator used for email in reactemail validation form in react using error messagejavascript validate email reactjsreact required input emailreact valid email jsckeck for email validation reactemail formate validation via react formemail input validation javascript reactvalidate email address with reactjsvalue includes email validation reactjsreact email validation npmemail validation from server using reactjsreact email validatorhow to use regex in email validation reactemail validator in reactvalidation on email and phone in reactjsemail format validation reactreact check for real email validationemail validation pattern reactreact js test valid email how to valid email in reactjs in funcvalidate email address in react jsreact email verify examplehow to email validation with reactemail validate reactemail validation reactjslive email validation with reactemail validator reactemail validation regex reactreact email validation codereact js validate emailinput type email react 5cinput type email custom validation reactemail id validation in react jsreact js verify emailcomposant email validation pour react jsemail validation reactc jshow to valid email in reactjs in functional componentcheck email validation reactemail validaotr reactvalidate email react react email validationreact js email field validationreact check email formathow to validate email input in reactemail address validation reactverify if email input value reactreactjs email validationemail validation reacthow to validate email in react jsemail validation example in reactinput type email react js validation