Choose what you want to validate, such as an email address, a phone number, a date or a postcode, or set your own rules for allowed characters and length, and get a ready regular expression. The tool explains each part in plain English, gives you the JavaScript line and the HTML pattern attribute to paste in, and lets you test a sample straight away. It builds from a library of checked patterns and a rule builder, so you do not need to know the syntax.
Most patterns are built from the same four ideas. A character class lists which characters are allowed in one position, such as [a-z0-9]. A quantifier says how many of them, such as {3,16} for three to sixteen. Groups with a question mark, such as (?:-\d{4})?, make a part optional. Anchors fix where the match must start and end.
Reading the breakdown table beside the pattern is a good way to learn the notation. Each row is one piece of the pattern with its meaning, from left to right, so you can see how the whole thing is assembled and adapt it by hand.
A strict pattern rejects more bad input but also rejects more good input. For something with a published standard, such as a hex colour or an IPv4 address, strict is right because the format is exact. For something free-form, such as a phone number or a name, forgiving is better: accept spaces, brackets and dashes, then clean the value in code.
Think about what a failure costs. A rejected real person leaves your form; an accepted bad value ends up in your database. If you can clean up bad values later, accept more at the door. If bad values cause harm, such as a malformed value used in a command or a query, be strict and validate again on the server.
A regular expression, or regex, is a compact pattern that describes a set of text strings. Programs use it to check input, find text and replace text. For example, ^\d{5}$ describes exactly five digits, such as a short ZIP code.
With anchors on, the pattern starts with ^ and ends with $, so the whole text must fit the pattern. With anchors off, the pattern can match a piece inside longer text, which is what you want when searching a paragraph for emails or colours.
The browser treats an HTML pattern attribute as if it were wrapped in ^(?: and )$, so it always has to match the whole value. The anchors would be redundant, and the tool leaves them out.
It writes a quantifier after the character class. A minimum of 3 and a maximum of 16 gives {3,16}; a minimum of 1 with no maximum gives +; equal minimum and maximum give an exact count such as {8}. If you tick must start with a letter, the first character gets its own class and the length counts include it.
They are practical patterns for the usual formats, not complete legal definitions. Phone numbers, postcodes and addresses vary by country and change over time, so treat the result as a first filter and test it on your real data.
Related: Regex tester, JSON formatter and validator, Hex colour picker.
Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.
We.Inc is an AI-powered website builder you can resell under your own brand. Launch a branded client dashboard, bill on Stripe Connect, and deliver AI-generated websites in minutes. White-label plans start at $99 a month for 25 client sites, with a 7-day free trial and no per-site fees.