Form Validation - What method do you use these days?
HTML Form Validation is heavily underused
html - HTML5 form validation without Javascript validation - Stack Overflow
Best JavaScript Form Validation Libraries
not really sure what will you do with that and why you even need it. There is required html tag, and anyway proper validation should be done in backend...
More on reddit.comVideos
I’m wondering what methods most people use for form validation these days.
I haven’t built a contact form in a while and I am updating a React front end with a form that was built using react-bootstrap. I need to add a ’Website’ input field to the form in case the user wants to include their website in their contact information. The old/existing form used html validation, but <input type=‘url’ /> requires the user to type ‘http://‘, which seems a bit annoying for the average non-tech person entering their website address. Also, <input type=‘email’ /> only requires an ‘@‘ with some text after it and does not require a domain such as ‘.com’, ‘.net’, etc.
So I am wondering…what do most do for validation?
Plain HTML validation
HTML validation with some sort of check and then prepending or appending when necessary
<form noValidate />and a completely separate logic for front end validationSomething else
In other words, the HTML5 validation is only a visual artifact; it does not prevent the form submission.
It's not how it is supposed to work. By design, HTML5 validation should prevent the incorrectly filled form from submission. And it does — in most browsers. Unfortunately, there is a bug in Safari that leads to the behavior you described. So until this bug if fixed, yes, you might need to validate the form with JS, too, but it's not because of the nature of HTML5 validation, only because of the lack of its support in Safari.
<form method="GET" action="Your Action Page" id="contact form">
<div class="form-group">
<label>Name</label>
<input type="text" name="name" placeholder="name" id="name" class="form-control" required="true" pattern="[a-zA-z]+">
</div>
<div class="form-group">
<label>Email</label>
<input type="email" name="email" id="email" placeholder="email" class="form-control" required="true" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$">
</div>
<div class="form-group">
<label>Mobile No:</label>
<input type="tel" name="number" id="number" placeholder="Phone No"pattern="^\d{10}$" required="true" oninput="this.value = this.value.replace(/[^0-9.]/g, ''); this.value = this.value.replace(/(\..*)\./g, '$1');" onkeydown="if(this.value.length==10 && event.keyCode!=8 && event.charCode != 9 && event.which != 9 ) return false">
</div>
<div class="submit-area">
<input type="submit" id="submit-contact" name="submit" class="btn-alt" value="Send Message">
<div id="msg" class="message"></div>
</div>
</form>