Waiting Answer November 04, 2023

How to Add Image Select Only Validation Rule in HTML?

Answers
2023-11-10 04:33:30

If we use <input type="file">, it will accept all file types. But it is possible to restrict the file types to only images, or certain image file extensions. To achieve this, we need to use the HTML accept attribute. This attribute is only used with <input type="file"> and serves as a filter to select file inputs from the file input dialog box.

Example for image select only validation,

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <input type="file" id="img" name="img" accept="image/*">
  </body>
</html>

 

Your Answer

Recently Asked Questions

PHP is a server-side scripting language designed for web development but also used as a general-purpose programming language.PHP is a server-side scripting language designed for web development but also used as a general-purpose programming language.

Python has a variety of libraries such as NumPy, pandas, and matplotlib that make it an ideal language for data analysis and visualization.

Java is commonly used for building enterprise-scale applications.