Regex for Checking for at Least One Special Character

Tests whether a string contains at least one non-alphanumeric character.

Published October 11, 2026

This regex tests whether a string contains at least one special (non-alphanumeric) character.

How the pattern works

Breaking the pattern down: [^A-Za-z0-9] = anything not a letter or digit.

Test your regex against both matching and non-matching inputs; use the Regex tool on this site to experiment live.

Pattern tests

/[^A-Za-z0-9]/
✓ 'abc!'
✓ 'a b'
✗ 'abc123'
✗ 'Z9'

Practical examples

The pattern

const re = /[^A-Za-z0-9]/

Test it

const re = /[^A-Za-z0-9]/
re.test('abc!')   // true
re.test('a b')   // true
re.test('abc123')   // false
re.test('Z9')   // false

In Python

import re
re.search(r'[^A-Za-z0-9]', text)

Common mistakes

  • Counting spaces as special characters unintentionally.
  • Escaping mistakes inside character classes.
  • Rejecting valid Unicode letters.

Key takeaways

  • Anchors (^ and $) make the whole string match instead of a part of it.
  • Regex checks format only; verify data separately when it matters.
  • Test with valid and invalid samples.

FAQ

Specific list instead?

Use [!@#$%^&*] to allow only chosen symbols.

Where can I test this pattern?

Use the Regex Tester on this site, or regex101.com.

More General articles