I need to validate images with regular expressions, with the following conditions:
$string
may be empty- I can receive a single image with this format, for example:
2017-06-01-03-55-00-5930782c5c0b1.jpg
- I can get several image names separated by commas example:
2017-06-01-03-55-00-5930782c5c0b1.jpg, 2017-06-01-03-55-00-5930782c5c0b1.jpg
- Avoid other special characters other than these:
A-Za-z0-9\-
I have managed to do this with my knowledge in regular expressions, but I have to validate, if the estring is empty, if there are several images separated by commas, and if there are no other characters than the string.
$pattern = '/[a-zA-Z0-9]\.(jpg|jpeg|png|gif)$/';
$string = '2017-06-01-03-55-00-5930782c5c0b1.jpg';
if( preg_match($pattern, $string) ) {
echo "TRUE";
} else {
echo "FALSE";
}
Thank you very much for your help, please.