Skip to main content
AllDevToolsHub
Back to all patterns

Password Without Spaces

Security

Validates that a password is at least 8 characters with no spaces.

/^\S{8,}$/

How it works

\S matches any non-whitespace character. This minimal pattern enforces a minimum length of 8 characters and disallows spaces, without restricting character types. Useful when you want to allow any characters (including Unicode) but not spaces.

Test Cases

Should Match

  • password1
  • P@ssw0rd!
  • correcthorsebatterystaple

Should NOT Match

  • short
  • has spaces here
  • 1234567

Quick Summary

Validates passwords with minimum 8 characters and no spaces. Allows any non-whitespace character including Unicode and special characters. More permissive than complexity-enforcing patterns.

Key Takeaways

Key Takeaways

  • \S matches any non-whitespace character, very permissive
  • Allows Unicode characters, emoji, and all special characters
  • Does not enforce complexity, combine with other checks if needed
  • NIST SP 800-63B recommends allowing all printable characters including spaces
Use Cases

When to use it

  • Permissive password validation that allows Unicode passphrases
  • Minimum-length check without character class restrictions
  • Validating API keys or tokens that must not contain spaces
Watch out

Common Mistakes

  • Using this as the only password validation, add a minimum length check and consider complexity requirements
  • Blocking spaces in passwords, NIST recommends allowing spaces for passphrases
FAQ

Password Without Spaces, Frequently Asked

Should passwords allow spaces?

NIST SP 800-63B recommends allowing all printable ASCII characters including spaces. Passphrases with spaces (correct horse battery staple) are more secure than complex short passwords.

What is the minimum recommended password length?

NIST recommends minimum 8 characters for user-chosen passwords, 6 for machine-generated. Consider requiring 12+ for sensitive applications.