Heya
im looking to validate a string and make sure it is the following format
"thumb_*.jpg|gif|png"
where * is a wildcard, and jpg|gif|png are optional file extensions
this is in PHP
Is that possible?
ps: i just want return value true or false
Heya
im looking to validate a string and make sure it is the following format
"thumb_*.jpg|gif|png"
where * is a wildcard, and jpg|gif|png are optional file extensions
this is in PHP
Is that possible?
ps: i just want return value true or false
$valid = preg_match('~^thumb_.*\.(jpg|gif|png)$~', $filename) != 0;
Or if you really want the extension to be optional:
$valid = preg_match('~^thumb_.*(\.(jpg|gif|png))?$~', $filename) != 0;
EDIT: As per Am's comment on Cletus' answer, you might want to restrict the wildcard to avoid matching slashes:
$valid = preg_match('~^thumb_[^/]*\.(jpg|gif|png)$~', $filename) != 0;