Regex for Social Handle (@)
Regex Pattern
^@[a-zA-Z0-9_]{1,30}$Social media handle with @ prefix (1-30 chars)
Quick Answer
The regex pattern for social handle (@) is `^@[a-zA-Z0-9_]{1,30}$`. Social media handle with @ prefix (1-30 chars). This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.
Test Examples
| Input | Result |
|---|---|
| @username | ✓ Matches |
| @John_Doe | ✓ Matches |
| @user123 | ✓ Matches |
| username | ✗ No match |
| @ | ✗ No match |
| @user-name | ✗ No match |
| @a@a@a@a@a@a@a@a@a@a@a@a@a@a@a@a@a@a@a@a@a@a@a@a@a@a@a@a@a@a@a@a | ✗ No match |
Code Examples
javascript
const regex = /^@[a-zA-Z0-9_]{1,30}$/;
const isValid = regex.test(value);python
import re
pattern = r'^@[a-zA-Z0-9_]{1,30}$'
if re.match(pattern, value):
print("valid")ruby
pattern = /^@[a-zA-Z0-9_]{1,30}$/
if value =~ pattern
puts "valid"
endphp
if (preg_match('/^@[a-zA-Z0-9_]{1,30}$/', $value)) {
echo "valid";
}java
String pattern = "^@[a-zA-Z0-9_]{1,30}$";
boolean isValid = value.matches(pattern);Frequently Asked Questions
Related Regex Patterns
UUID v4
UUID version 4 (randomly generated)
UUID (Any Version)
Any RFC 4122 UUID (versions 1-5)
JWT Token
JSON Web Token (header.payload.signature)
Hex String
Any-length hexadecimal string
Base64 String
Standard base64 encoded string
Alphanumeric Username
Username with letters, digits, underscores (3-16 chars)