24 December 2008

Regular Expression for File Upload Validation

This is a Regular Expression for validating the file upload HTML/ASP.NET control on the client side using JavaScript!

" ^.+\.(([jJ][pP][eE]?[gG]) | ([gG][iI][fF]) | ([bB][mM][pP­]) | ([pP][nN][gG]) |([wW][mM][fF]))$ "

As you can see you can specify any file format between the | | fields which stand for OR.
You can use this function in ASP.NET 2.0 with the Regular Expression Validator or can use the JavaScript RegExp function for PHP.

Note: Its always a good idea to validate the user input on the server side!!

No comments: