JSFiddle - React, Tailwind, and code Playground

by calder12

HTML

<form id="testForm">
<input type="text" id="phone" />
<input type="submit" id="submit"/>
<div class="error"></div>

CSS

div {
  margin: 20px;
  cursor: pointer;
}

JavaScript

$("#testForm").on("submit", function(){
	if(!$.trim($(".error").html()).length) {
		//This is the submit part if the validation error doesn't exist.
  	$("#testForm").submit();
  } else {
  // This can just be return false or some code that updates the error, highlights some shit whatever to get the users attention.
  	$(".error").html("We told you that phone number was wrong!");
  	return false;
  }
})