开发者

Picture file jQuery validation plugin

H开发者_如何转开发ow to get an field required with the jQuery Validation plugin ? Couldnt find this one in the doc/demos.

I mean there's the option for an email which is class="required email" same for a number class="required number" but nothing about a file input.


You can't check that a submitted file is an image format at the client side, because the client side has no access to read the file.(*) That's why the plugin doesn't offer such a feature.

The only reliable check you can do on a file upload field to to check that its value is not an empty string (no file selected). Whilst you might be tempted to guess whether a file is an image by looking at the filename (eg. does it end in ‘.gif’, ‘.png’, ‘.jpeg’ or ‘.jpg’), this is unreliable as depending on the operating system and filetype configuration settings a file extension may well not bear any relation to the type of file.

(*: Except in Firefox 3 using the FileList interface.)


Just try using the

class='required error'

to ensure there's something in the field. The class="required email" and class="required number" look for certain patterns.

If you want to ensure the upload has .jpg in the filename then write a custom rule to check for those characters.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜