Need RegExp for image file validation

P

paulmcnally

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.
 
E

Evertjan.

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.
 
E

Elegie

Evertjan. said:
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.
No coffee, why are you not tested?

They weren't that friendly so I escaped :)

Cheers.
 
E

Evertjan.

Elegie wrote on 24 sep 2006 in comp.lang.javascript:
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 ;-{
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,110
Latest member
OdetteGabb
Top