Mootools image type validation

82 views
Skip to first unread message

vargatom

unread,
Oct 7, 2012, 6:11:34 AM10/7/12
to moof...@googlegroups.com
Hi,


I would like to create an image validation field but it is not work.


        <fieldset>
            <legend>File</legend>
                <label><span>Your image : </span>
                    <input type="file" class="validate['required','image'] text-input" name="file" />
                </label>
        </fieldset>

problem: this version accept all files and not sign that this input wait for image filetypes

Can anybody help me?
Thanks!

jmwfr

unread,
Oct 8, 2012, 9:06:38 AM10/8/12
to moof...@googlegroups.com
Hello,

If your problem is to make the file browser showing only image files when clicking on browse, you've to use the "accept" parameter for the field, i.e:

 <input type="file" class="validate['required','image'] text-input" name="file" accept="image/*" />

But I think it doesn't work on all browsers...

Else, I don't understand your problem, this should work, when user try to upload something else than a file with jpg, jpeg, png, gif or bmp an error message is displayed.

The image field check is based on a regexp (default is "/.(jpg|jpeg|png|gif|bmp)$/i" allowing only jpg,jpeg,png,gif, and bmp) that you can modify when you initialize the script.

i.e :

window.addEvent('domready', function(){check = new FormCheck('name of you form', {
            display : {
                You display options here...
            }
           
            regexp : {
                image : you custom regex here...
            }
        })});

If the extension of the file selected within the file field doesn't match the regexp an error message is displayed saying "This field should only contain image types".

Hope it helps! ;)

Best regards,

Jean-Marc
Reply all
Reply to author
Forward
0 new messages