Validate emails and URLs in PHP
Use filter_var to validate email addresses and http(s) URLs, with an allow-list for schemes.
Loading snippets…
10 snippets
Use filter_var to validate email addresses and http(s) URLs, with an allow-list for schemes.
Safely turn unknown JSON into a typed result by validating its shape instead of casting.
A fetch wrapper that throws on HTTP errors and validates the JSON body with a type guard.
Validate and normalize fields in __post_init__ so invalid objects can never be created.
Parse JSON with exceptions on error and a depth limit, instead of silently getting null.
Model success and failure as a discriminated union so callers must handle both cases.
Replace "as any" on parsed JSON with small type guards that check shape at runtime.
List values that appear more than once with GROUP BY and HAVING, including how many times.
Make the compiler fail when a union gains a new member that a switch does not handle.
Associate labels, help text and validation errors with an input so screen readers announce them.