Image File Check Java Example
image file check java example for production applications
Pattern Views
44,434
↗ 12.5%Last 30 days
Community Rating
⭐
94%
454 likes
Regular Expression
/\.(jpg|jpeg|png|gif|pdf|doc|docx)$/
Explanation
This regex pattern validates image file check java example. Commonly used by developers for input validation and form checking.
Code Examples
JavaScript Example
javascript
// image file check java example - JavaScript
const regex = /\.(jpg|jpeg|png|gif|pdf|doc|docx)$/;
function validate(input) {
if (!input || typeof input !== 'string') return false;
return regex.test(input.trim());
}
// Usage examples
console.log(validate('image.jpg')); // true
console.log(validate('file.exe')); // falsePython Example
python
# image file check java example - Python
import re
pattern = r"\.(jpg|jpeg|png|gif|pdf|doc|docx)$"
regex = re.compile(pattern)
def validate(input_str):
if not input_str or not isinstance(input_str, str):
return False
return bool(regex.match(input_str.strip()))
# Usage examples
print(validate('image.jpg')) # True
print(validate('file.exe')) # FalsePHP Example
php
<?php
// image file check java example - PHP
function validate($input) {
if (!is_string($input) || empty(trim($input))) {
return false;
}
$pattern = '/\.(jpg|jpeg|png|gif|pdf|doc|docx)$/';
return preg_match($pattern, trim($input)) === 1;
}
// Usage examples
var_dump(validate('image.jpg')); // bool(true)
var_dump(validate('file.exe')); // bool(false)
?>PHP Example
java
// Image File Check Java Example - Java
import java.util.regex.Pattern;
public class RegexValidator {
private static final Pattern pattern = Pattern.compile("\.(jpg|jpeg|png|gif|pdf|doc|docx)$");
public static boolean validate(String input) {
if (input == null || input.trim().isEmpty()) {
return false;
}
return pattern.matcher(input.trim()).find();
}
// Usage examples
public static void main(String[] args) {
System.out.println(validate("test-input")); // Check pattern match
}
}Test Cases
✓ Should Match
image.jpg
document.pdf
✗ Should NOT Match
file.exe
no-ext
Performance
Speed
optimized
Memory
efficient