REGEXVAULTv2.0
Dev & Systems/File Paths
Verified Safe

POSIX File Permission Octal Regex for JavaScript

/^([0-7]?)([0-7]{3})$/

What this pattern does

This page provides a lightweight, single-purpose regular expression for matching posix file permission octal, ported and verified for JavaScript. A rigorously tested regex reduces debugging time and protects your application from edge-case failures. The snippet below is ready to drop into your JavaScript project — whether you're validating in an Express middleware, a Next.js API route, or a client-side form.

Javascript Implementation

Javascript
// POSIX File Permission Octal
// ReDoS-safe | RegexVault — Dev & Systems > File Paths

const posixFilePermissionOctalRegex = /^([0-7]?)([0-7]{3})$/;

function validatePosixFilePermissionOctal(input: string): boolean {
  return posixFilePermissionOctalRegex.test(input);
}

// Example
console.log(validatePosixFilePermissionOctal("755")); // true

Test Cases

Matches (Valid)
Rejects (Invalid)
755888
64499
77776
0008888
0755a644
47550855
2755
1777

When to use this pattern

This pattern is drawn from the Dev & Systems > File Paths category and carries a ReDoS-safe certification. That matters for JavaScript developers because especially critical in long-running Node.js event loops where a ReDoS vulnerability can block the entire process. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.

Common Pitfalls

Setting 777 on sensitive files is a security risk. The sticky bit on directories (1777) prevents users from deleting each other's files even with directory write permission.

Technical Notes

Optional leading digit: 4=setuid, 2=setgid, 1=sticky. Three digits: owner/group/other (read=4, write=2, execute=1). 1777 = /tmp permissions (sticky). 4755 = setuid root (dangerous). Group 1 = special bits, group 2 = rwx permissions.

Have a pattern that belongs in the vault?

Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.

Submit a Pattern