Reactjs Form Validation Example with Demo

Today, We want to share with you Reactjs Form Validation Example with Demo.In this post we will show you Reactjs – Form input validation, hear for Up and Running with React Form Validation we will give you demo and example for implement.In this post, we will learn about How to do Simple Form Validation in Reactjs with an example.

Reactjs Form Validation Example with Demo

There are the Following The simple About Reactjs Form Validation Example with Demo Full Information With Example and source code.

As I will cover this Post with live Working example to develop react form validation best practices, so the react form validation npm for this example is following below.

Step 1: Reactjs Part

React + No-Library (pure JS)

class Product extends React.Component {

    this.state = {
      fields: {},
      errors: {}

    let fields = this.state.fields;
    let errors = {};
    let formIsValid = true;

    //here User Name
      formIsValid = false;
      errors["name"] = "Sorry, To have Cannot be empty";

    if(typeof fields["name"] !== "undefined"){
        formIsValid = false;
        errors["name"] = "Only letters";

    //check User Email
      formIsValid = false;
      errors["email"] = "Cannot be empty";

    if(typeof fields["email"] !== "undefined"){
      let lastAtPos = fields["email"].lastIndexOf('@');
      let lastDotPos = fields["email"].lastIndexOf('.');

      if (!(lastAtPos  0 && fields["email"].indexOf('@@') == -1 && lastDotPos > 2 && (fields["email"].length - lastDotPos) > 2)) {
        formIsValid = false;
        errors["email"] = "Email is not valid";
    this.setState({errors: errors});
    return formIsValid;

      alert("Form submitted");
      alert("Form has errors.")


  handleChange(field, e){    		
    let fields = this.state.fields;
    fields[field] =;        

    return (

) } } ReactDOM.render(, document.querySelector("#root"))

Step 2: HTML Part


Step 3: CSS Part


  margin: 20px;

  margin-bottom: 5px;
  height: 20px;
  border: 1px solid #d8d8d8;
  padding: 3px;

  border: 1px solid #d8d8d8;
  padding: 3px;

  padding: 10px;
  border: 1px solid #d8d8d8;
  background-color: #f9f9f9;
  border-radius: 3px;

  margin-left: 5px;
  font-size: 13px;
  color: red;

Reactjs – Form input validation

Web Programming Tutorials Example with Demo

Read :


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Reactjs Form Validation Example with Demo.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment