0

I'm validating form fields.I tried this regex for image '/^[.jpg|.png|.gif|.bmp]$/i but i think is regex is not correct.

How do i validated links,i only want to check whether the link has HTTP/HTTPS/WWW

Proper link should be . I do not wnat ot check domain,i see many domains ending in different forms line .rs etc.

Any help would be appreciated!

2
  • No your regex shouldnt have starts with .jpg if thats done on the whole name - you would need to show code, errors, etc. Commented Jun 19, 2012 at 11:28
  • @BugFinder:If i upload .jpg ,it is showing upload only images error.My regex is wrong.What is the regex to validate photos. Commented Jun 19, 2012 at 11:29

2 Answers 2

2

Check image format (format case-insensitive):

"([^\s]+(\.(?i)(jpe?g|png|gif|bmp))$)"

Examples :

"Test.jpg" OK
"Test.JPEG" OK
"Test.BMP" OK

Check url (HTTP or HTTPS or WWW):

"((http:\/\/|https:\/\/)?(www.)?(([a-zA-Z0-9-]){2,}\.){1,4}([a-zA-Z]){2,6}(\/([a-zA-Z-_\/\.0-9#:?=&;,]*)?)?)"
Sign up to request clarification or add additional context in comments.

2 Comments

:Images and link regex separately.
:What does question mark do in image format.It will only check whether user has uploaded image only not any thing else.
0

To validate images, this is the regex:

'/\.(jpg|png|gif|bmp)$/i'

You can add any postfixes as needed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.