473,387 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Need RegExp for image file validation

Hi,

I need a javascript RegExp for image file validation from a file upload
form.

I need to allow image files only (jpeg/jpg/gif/png)

can anybody help me please?

thanks,

Paul.

Sep 24 '06 #1
5 3203
wrote on 24 sep 2006 in comp.lang.javascript:
I need a javascript RegExp for image file validation from a file upload
form.
need != want
I need to allow image files only (jpeg/jpg/gif/png)
Extention testing != file testing
can anybody help me please?
var isImageExtention = /.\.(jpe?g||gif||png)$/i.test(t);

Not tested.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 24 '06 #2
Evertjan. wrote:
var isImageExtention = /.\.(jpe?g||gif||png)$/i.test(t);
....which allows ghost extension, too :)
Not tested.
Me neither, shame on us, coffee break?
Sep 24 '06 #3
Elegie wrote on 24 sep 2006 in comp.lang.javascript:
Evertjan. wrote:
>var isImageExtention = /.\.(jpe?g||gif||png)$/i.test(t);

...which allows ghost extension, too :)
Please explain.
>Not tested.

Me neither, shame on us, coffee break?
No coffee, why are you not tested?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 24 '06 #4
Evertjan. wrote:
>>var isImageExtention = /.\.(jpe?g||gif||png)$/i.test(t);
...which allows ghost extension, too :)

Please explain.
alert(/.\.(jpe?g||gif||png)$/i.test("foo."));

The syntax of regular expressions defines a single pipe as separator for
alternatives, doubling them results in your final production allowing no
extension at all.
>>Not tested.
Me neither, shame on us, coffee break?

No coffee, why are you not tested?
They weren't that friendly so I escaped :)

Cheers.
Sep 24 '06 #5
Elegie wrote on 24 sep 2006 in comp.lang.javascript:
Evertjan. wrote:
>>>var isImageExtention = /.\.(jpe?g||gif||png)$/i.test(t);
...which allows ghost extension, too :)

Please explain.

alert(/.\.(jpe?g||gif||png)$/i.test("foo."));

The syntax of regular expressions defines a single pipe as separator for
alternatives, doubling them results in your final production allowing no
extension at all.
That's why I didn't test ;-{
>>>Not tested.
Me neither, shame on us, coffee break?

No coffee, why are you not tested?

They weren't that friendly so I escaped :)

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 24 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: CSDunn | last post by:
Hello, I need to apply validation to two text boxes. One text box named FirstNumber is required to contain only numbers, and be only three digits long. The other text box named SecondNumber...
5
by: J. J. Cale | last post by:
Little astrology program has 2 text input boxes for birth dates. There are 3 selects for day month year that will supply output to whichever text input had the focus last. If the user picks from...
3
by: phal | last post by:
Hi all; I code Perl for CGI, I using regular expression to check the validation of user input, because the form is small and it run only from my own computer, anyways if many people using my...
12
by: Dag Sunde | last post by:
My understanding of regular expressions is rudimentary, at best. I have this RegExp to to a very simple validation of an email-address, but it turns out that it refuses to accept mail-addresses...
8
by: Dmitry Korolyov | last post by:
ASP.NET app using c# and framework version 1.1.4322.573 on a IIS 6.0 web server. A single-line asp:textbox control and regexp validator attached to it. ^\d+$ expression does match an empty...
26
by: Matt Kruse | last post by:
Are there any current browsers that have Javascript support, but not RegExp support? For example, cell phone browsers, blackberrys, or other "minimal" browsers? I know that someone using Netscape...
6
by: Christoph | last post by:
I'm trying to set up client side validation for a textarea form element to ensure that the data entered does not exceed 200 characters. I'm using the following code but it doesn't seem to be...
3
by: Milagro | last post by:
Hello Everyone, I'm trying to debug someone elses php code. I'm actually a Perl programmer, with OO experience, but not in php. The code is supposed to upload a photo from a form and save it...
4
by: yatin | last post by:
hi, friend. i have a problem in image validation plz check it. i have to include a image validation in foam 1. but i sending a details through form2. But when i include a image validation in foam1,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.