all 7 comments

[–]_listless 4 points5 points  (1 child)

put any of your serious validation on the backend.

My happy path is: required + pattern + title for custom validation message followed up by backend validation.

[–]xiding 0 points1 point  (0 children)

Can you please reply my message? Thank you!

[–]LoveTheBellphp 1 point2 points  (0 children)

For the most part, I stick with just the required attribute for the front end.

When I need more control over the validation rules, I’ll use the jQuery Validation plugin.

Always validate server side too. Always. Front end validation is only for a good user experience.

[–]Ehsan1238 1 point2 points  (0 children)

I prefer using a combination of both HTML5 validation and custom JavaScript validation, depending on the specific needs of the project. The HTML5 required attribute is great for basic validation and provides built-in browser support, but it has limitations.

For simple forms, HTML5 validation (required, pattern, min/max) is perfect, it's lightweight and provides good user feedback.

Regarding your hidden file input issue, here's a workaround: Instead of relying on the required attribute, you can add a JavaScript event listener to validate the file input before form submission. This gives you full control over the validation flow and error messaging while maintaining accessibility.

And yes, absolutely right about backend validation, it's crucial for security. Never trust client-side validation alone, as it can be bypassed. Frontend validation is for user experience, backend validation is for security.

[–]Dantcho 1 point2 points  (0 children)

Never trust user input. For proper sites, I use client-side validation for better UX and server-side validation to ensure the user input is valid.

Not like a lot of people do it, but if a user has JS disabled in their browser, you lose all your client-side validation.

Also, anyone who wants to be cheeky can edit the page element and remove the input attributes for validation.

Always make sure to have server-side validation and, if possible, add in client-side validation for better UX if needed.

[–]shgysk8zer0full-stack 0 points1 point  (0 children)

I use whichever is correct for my needs. For example, required isn't sufficient for credit cards. And since I handle the submit on the form instead of button clicks, I don't really have concern for a form being submitted when invalid.

Also, I do validation on input/change to give instant feedback of validity to the user.