惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
The Last Watchdog
The Last Watchdog
TaoSecurity Blog
TaoSecurity Blog
PCI Perspectives
PCI Perspectives
L
LINUX DO - 最新话题
H
Heimdal Security Blog
S
Security Archives - TechRepublic
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Troy Hunt's Blog
SecWiki News
SecWiki News
S
Secure Thoughts
The Cloudflare Blog
Last Week in AI
Last Week in AI
Google DeepMind News
Google DeepMind News
Attack and Defense Labs
Attack and Defense Labs
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
量子位
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
V
Visual Studio Blog
N
News and Events Feed by Topic
E
Exploit-DB.com RSS Feed
博客园 - Franky
博客园 - 司徒正美
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
酷 壳 – CoolShell
酷 壳 – CoolShell
Know Your Adversary
Know Your Adversary
M
MIT News - Artificial intelligence
V
V2EX
Webroot Blog
Webroot Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Cyberwarzone
Cyberwarzone
博客园 - 【当耐特】
月光博客
月光博客
Y
Y Combinator Blog
B
Blog RSS Feed
Recent Announcements
Recent Announcements
S
Schneier on Security
H
Hacker News: Front Page
Stack Overflow Blog
Stack Overflow Blog
NISL@THU
NISL@THU
小众软件
小众软件
雷峰网
雷峰网
P
Privacy International News Feed
腾讯CDC
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
C
Cyber Attacks, Cyber Crime and Cyber Security
V
Vulnerabilities – Threatpost
H
Hackread – Cybersecurity News, Data Breaches, AI and More
N
News and Events Feed by Topic

Resend RSS Feed

6 Tips for Accessible Emails Welcoming Manoel do Amaral, our new Brand Designer Welcoming Michael Vaz, our new Customer Success Engineer Six Steps to Improve Your Sender Reputation Welcoming Tatira Andrade, our new Executive Assistant Welcoming Pedro Ivo Hudson, our new Design Engineer Welcoming Diel Duarte, our new Open source Engineer Welcoming Areia Spinner, our new Recruiter Resend Forward: A Conference about Craft React Email 6.0 Custom Tracking Domains AI Email Editor Introducing Automations Welcoming Ahmed Tolba, our new SRE Engineer Welcoming Aneil Singh, our new Founding Account Executive Welcoming Lucas Motta, our new Software Engineer Welcoming Trey Knowles, our new Founding Account Executive Welcoming Anxhela Carciu, our new SRE Engineer Introducing DMARC Analyzer Welcoming Evan Thibodeau, our new Customer Success Engineer Welcoming Derich Pacheco, our new Software Engineer Welcoming Alec Ventura, our new Data Engineer Welcoming Felipe Freitag, our new Software Engineer Welcoming Mateusz Wos, our new Software Engineer Incident report for February 15, 2026 Email automation for OpenClaw How to Create a DevTools Agent Skill Introducing Email Skills Why You Should Embrace the Promotions Tab Slater Smith, our new Customer Success Engineer Do You Need a Warmup Service? Welcoming Zá Scalon, our new Brand Designer How Replit Built Effortless Email Sending Features 1,000,000 users Top 10 new features in 2025 Welcoming Danilo Campos, our new Design Engineer How Dub Uses Webhooks to Power Features Incident report for November 18, 2025 Resend Forward 5: Wrap Up One More (AI) Thing React Email 5.0 Unsubscribe Topics New Contacts Experience Introducing Templates Inbound Emails $3M to Make Email Safer Hacktoberfest 2025 Four Ways to Hurt Your Sender Reputation Resend MCP Hackathon Welcoming Christina Martinez, our new Developer Experience Engineer How to read a DMARC report Welcoming Erin Levine, our new Chief of Staff Engineering an AI App Welcoming Lucas da Costa, our new Software Engineer Welcoming Lucas Vieira, our new Software Engineer Resend acquires Briefer How Raycast Modernized their Email Sending How to Get Email Consent DMARC Policy Modes Welcoming Gabriel Miranda, our new Software Engineer Rebranding Resend The 7 Best Email Verification APIs for Developers How DMARC Applies to Subdomains Welcoming Pedro Gomes, our new Software Engineer Do You Need a Dedicated IP? The 6 best notification infrastructure services The Fixer Why Your Emails are Going to Spam Engineering Idempotency Keys Microsoft’s bulk sending requirements for 2025 Welcoming Rehan van der Merwe, our new Devops Engineer 400,000 users and beyond Welcoming Cassio Zen, our new Software Engineer Resend acquires Mergent How to warm up a new domain Welcoming Carolina Josephik, our new Software Engineer Launch Week: Behind the Scenes Welcoming Isabella Aquino, our new Software Engineer Resend Forward 4: Wrap Up React Email 4.0 Multiplayer Editor Broadcast API Multiple Teams new.email Public Launch Welcoming Anna Ward, our new Postmaster How Gumroad Migrated 100M Emails to Resend Welcoming João Melo, our new Software Engineer Welcoming Jp Valery, our new Customer Success Engineer What is AX (Agent Experience) and how to improve it Welcoming Pauline Chin, our new Customer Success Engineer Introducing new.email How we use Friction Logs to improve the product Top 10 Email Deliverability Tips Welcoming Giovana Yahiro, our new Designer Engineer What BIMI's Changes Mean for Email Top 10 new features in 2024 Design Engineering an X Component Welcoming Alexandre Cisneiros, our new Software Engineer Resend raises $18M Series A Welcoming Danilo Woznica, our new Designer Engineer
How to Validate Form Inputs
Chris Pennington · 2025-08-29 · via Resend RSS Feed

Form validation is a critical part of every web application, impacting user experience, data quality, and security.

Collecting user input is crucial in many email flows, including:

  • Waitlist sign-ups
  • Contact forms
  • Newsletter subscriptions
  • Support tickets
  • Feedback forms

The key is to balance usability with security. Let's look at some key tips for creating validated form inputs that are robust, accessible, and resistant to common attacks, all while still allowing legitimate users to complete forms smoothly.

1. Require necessary fields

Any required fields should include the required attribute. Adding the required attribute provides a basic level of client-side validation and maintains best accessibility practices.

You should also visually identify any required field so your users can immediately identify required information, like adding an asterisk or a label with a required indicator on an email input field for a newsletter subscription.

2. Use proper input types and attributes

HTML5 offers a wide range of input types that include built-in validation and are accessible by default. As a starting point, choose the input type that best fits your need (e.g., email, number, date, tel, etc.). Always supplement these with clear label elements for accessibility and context.

Inputs also include attributes that can help you validate inputs (like maxlength, min, max, or step). Of special interest for collecting emails is the pattern attribute. It provides a regular expression the input must pass to be accepted and works with these input types: text, search, url, tel, email, and password.

This pattern ensures that the input contains a non-whitespace string, followed by "@", followed by a non-whitespace string. Be careful of being too restrictive with the pattern, as it may prevent users from entering valid email addresses.

While helpful, these validation attributes only cover basic use-cases and only client-side.

3. Validate client-side and server-side

After you properly implement HTML input types and attributes, use a library for more precise validation. While TypeScript provides a level of safety during development, TypeScript does not do runtime validation.

Popular runtime validation libraries include:

  • Zod: comprehensive type validation with a powerful schema builder
  • Valibot: type validation with a modular API and minimal bundle size
  • Validator.js: lightweight and powerful library for string input validation and sanitization

Typically you define a schema that describes the expected structure and format of the input data.

At runtime, use the schema to validate the input data, providing detailed error messages if the input is invalid.

You should run server-side validation as well using the same library to ensure data integrity and protect against direct submissions to your API endpoints (e.g., by disabling JavaScript or manipulating requests).

While client-side validation is insufficient, it's still important for several reasons:

  • Provides immediate feedback: Validating client-side offers a quicker feedback loop and a better user experience.
  • Limits unnecessary server calls: Adding client-side validation can limit users from easily hitting your server endpoints when their inputs don't match your requirements.
  • Improves accessibility: Client-side validation can help users who rely on assistive technologies, such as screen readers, by providing immediate feedback on input errors.
  • Saves server resources: Client-side validation can reduce the load on your server by preventing invalid requests from reaching it.

4. Validate on blur

Validate user inputs on blur (i.e., after they move to the next input).

Early validation is often intrusive and annoying. If, however, you wait until form submission to show any errors, suddenly multiple errors can be displayed at once or your users may need to scroll to see the errors preventing form submission.

Validating user inputs on blur:

  • gives immediate feedback
  • shows errors in context
  • shows a single error at a time

If a user fails to provide a valid email address, they should be prompted to correct it while still in context, not long after on form submission.

5. Provide clear, inline error messages

For each input, have a corresponding error field to display relevant errors. Consider wording, styling, and accessibility.

Provide clear wording

Follow these best practices for your messages.

  • Avoid technical jargon.
  • Provide specific errors, avoiding generic messages.
  • Use plain language that explains what went wrong and how to fix it.

Show distinct error styling

Your error messages should include visual cues to help users identify the error and related field.

Consider accessibility

For user-created errors (like form inputs), it's important to mark the invalid input with aria attributes to provide clear feedback to assistive technologies.

On error input, set aria-invalid="true" using JavaScript.

Associate the error message using the aria-errormessage attribute, linking it by referencing the id.

You can also apply an aria-live property or use a live region role like alert for more direct feedback. A proper form library should include these accessibility details and is often the best way to ensure accessibility.

6. Protect against bots

It's important to safeguard against bots without annoying users. Consider implementing one or more of these techniques:

Add a honeypot field

A honeypot field is a hidden input field that is ignored by real users, but often filled out by bots. You can add a honeypot field by using the hidden attribute.

When the form is submitted, check to see if the form is filled out and reject the submission if it is.

Unfortunately, many bots cleverly avoid these honeypot fields, so we recommend only implementing this if you have also added at least one other bot detection method.

Add a CAPTCHA

A CAPTCHA is a test that is designed to be easy for humans to pass but difficult for bots to solve. Ideally, choose an invisible CAPTCHA that doesn't degrade the human experience while still providing a high level of security.

Consider one of the popular CAPTCHA services:

  • Google reCAPTCHA: helps you detect abusive traffic on your website without user interaction. reCAPTCHA v3 returns a score so you can choose the most appropriate action for your website.
  • Cloudflare Turnstile: confirms web visitors are real and blocks unwanted bots without slowing down web experiences for real users.
  • Vercel BotID: an invisible CAPTCHA that protects against sophisticated bots without showing visible challenges or requiring manual intervention

7. Sanitize and escape all inputs

Beyond validation, sanitize and escape all user inputs before processing or rendering them. Sanitization helps prevent injection attacks such as SQL injection and cross-site scripting (XSS).

One popular library for sanitization is DOMPurify, although we recommend using Isomorphic DOMPurify if your backend is Node.js, as it provides the same functionality on both client and server.

On a related note, consider trimming inputs as shown above to ensure user inputs do not contain unnecessary whitespace.

8. Monitor for suspicious patterns

If a user or bot avoids your current protections, it's important to monitor for suspicious patterns. These patterns can include:

  • Rapid submissions
  • Repeated IPs
  • Nonsensical input
  • Invalid email addresses

You can protect against these types of attacks by implementing additional measures:

  • Rate-limit your submissions to prevent spam and abuse (typically by limiting the number of requests by a given IP address).
  • Validate headers, cookies, and submission timing server-side to filter out basic bots.
  • Block (or require additional authentication for) known VPNs or ISPs that enable bad actors. You can find public ASN lists (Autonomous System Number) that provide information about these malicious networks and check against them during submission.

When observing suspicious patterns, be mindful that some methods involving user data (like storing IP addresses, etc.) may require disclosure to comply with privacy laws and regulations.

If receiving email addresses, consider verifying them upon form submission, which can help prevent high bounce rates and avoid damaging your sender reputation. View our Best Email Verification APIs Guide for more help.

Conclusion

Effective form validation should be useful and painless for good actors and frustrating and painful for bad actors. Regularly revisit your validation strategy, keep up with new best practices, and always put your users first.

By combining smart client-side checks, robust server-side validation, clear error messaging, and proactive bot/spam defenses, you’ll build forms that are both user-friendly and resilient against attacks.