Skip to main content

Check out common JavaScript regular rules, matching examples, and validation boundaries, and copy and test them yourself.

nonnegative integer

^(?:0|[1-9][0-9]*)$

Match example: 2048

Only ASCII digits are allowed, no extra leading zeros are allowed.

signed integer

^[+-]?(?:0|[1-9][0-9]*)$

Match example: -42

Do not check whether the value exceeds the JavaScript safe integer range.

simple decimal number

^[+-]?[0-9]+(?:\.[0-9]+)?$

Match example: -12.50

Exponents, thousandth separators, or decimals with omitted integer parts are not accepted.

Hexadecimal color

^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$

Match example: #3b82f6

Only handles 3-bit and 6-bit RGB, does not include transparency and CSS color names.

UUID text shape

^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$

Match example: 550e8400-e29b-41d4-a716-446655440000

Only characters and groups are verified, version bits, variant bits, or uniqueness are not verified.

date text shape

^[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12][0-9]|3[01])$

Match example: 2024-02-29

Only checks the format, does not validate leap years or days of the month, e.g. February 31st will still be rejected by the date parser.

Simple email box shape

^[^\s@]+@[^\s@.]+(?:\.[^\s@.]+)+$

Match example: [email protected]

This is not a standard verification of a complete email address; actual email existence requires a verification email to be sent.

ASCII identifier

^[A-Za-z_][A-Za-z0-9_]*$

Match example: user_id2

Does not include Unicode identifiers or exclude programming language reserved words.

IPv4 decimal address

^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])$

Match example: 192.168.1.1

Each segment ranges from 0 to 255, leading zeros, ports, CIDR, or IPv6 are not accepted.

White space characters

\s+

Match example: a b

JavaScript's whitespace set is not equal to all visual whitespace; this template is for lookup, not full paragraph validation.

Open the regular expression tester

Instructions for use

  1. Enter keywords to filter the regular template.
  2. Check the matching examples and applicable scope of the template, paying special attention to semantic restrictions such as date and email address.
  3. After copying the regular pattern, continue testing with your own normal and abnormal samples.

Input and output examples

Example input
^[A-Za-z_][A-Za-z0-9_]*$
Example output
user_id2

These are demo inputs and sample results, and do not mean that your data has been processed.

Calculation basis and reference materials

The template only addresses the scope listed in the description and does not replace complete business verification; dates and email addresses require additional semantic checks.

Content check: · About this site and content description

Related tools