DD
DevDash

Regex for Unix Timestamp

Regex Pattern

^\d{10}(?:\.\d{1,6})?$

Unix timestamp in seconds (10 digits) with optional microseconds

Quick Answer

The regex pattern for unix timestamp is `^\d{10}(?:\.\d{1,6})?$`. Unix timestamp in seconds (10 digits) with optional microseconds. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.

Test Examples

InputResult
1681234567✓ Matches
1609459200✓ Matches
1681234567.123456✓ Matches
168123456✗ No match
16812345678901✗ No match
notanumber✗ No match

Code Examples

javascript

const regex = /^\d{10}(?:\.\d{1,6})?$/;
const isValid = regex.test(value);

python

import re
pattern = r'^\d{10}(?:\.\d{1,6})?$'
if re.match(pattern, value):
    print("valid")

ruby

pattern = /^\d{10}(?:\.\d{1,6})?$/
if value =~ pattern
  puts "valid"
end

php

if (preg_match('/^\d{10}(?:\.\d{1,6})?$/', $value)) {
    echo "valid";
}

java

String pattern = "^\\d{10}(?:\\.\\d{1,6})?$";
boolean isValid = value.matches(pattern);

Frequently Asked Questions

Related Regex Patterns

Want API access + no ads? Pro coming soon.