5 useful Input Attributes

Hi, this #day-33, we are going to discuss 5 useful input attributes.

pattern

this attribute is almost used with a title attribute that describes the input’s pattern, its role is to specify a valid JavaScript regular expression that the in…


This content originally appeared on DEV Community and was authored by Aya Bouchiha

Hi, this #day-33, we are going to discuss 5 useful input attributes.

pattern

this attribute is almost used with a title attribute that describes the input's pattern, its role is to specify a valid JavaScript regular expression that the input field's value is checked against when the form is submitted. It works with the following input types: (text, email, tel, password, search, url, date).
more details

<form>
    <input
        type="text"
        placeholder="full name..."
        pattern="[A-z]{8,16}"
        title="the full name should be between 4 and 15 letters"
    />
    <input type="submit" />
</form>

Output:

input attributes Aya Bouchiha

maxlength

maxlength is an input attribute that specifies the maximum length of characters allowed in an input field. And when the length of the input's value is equal to the maxlength, the input field will not accept more characters.

<form>
    <input type="password" placeholder="phone password..." maxlength="4" />
    <input type="submit" />
</form>

Output:
After reaching 4 characters, the input field doesn't accept more characters.

input attributes Aya Bouchiha

autocomplete

this attribute specifies whether the browser can predict the input's value and displays options to fill in the field when a user starts typing or not. This attribute works with the following input type (text, tel, email, password, search, url, date pickers, color, range) <input> and <form> as well.

<form>
    <input
        type="text"
        placeholder="first name"
        name="f-name"
        autocomplete="on"
    />
    <input type="email" placeholder="email" name="email" autocomplete="off" />
    <input type="submit" />
</form>

Output:

input attributes Aya Bouchiha

autofocus

autofocus is an attribute that specifies that an input field should automatically get focus when the page loads or not.

<form>
 <input type="text" placeholder="your name..." autofocus />
 <input type="submit" />
</form>

Output:

input attributes Aya Bouchiha

list

This attribute refers to a <datalist> element that contains pre-defined options for an <input> element.
more details

<form>
    <input  list="programming-languages" />
    <datalist id="programming-languages">
        <option value="java" />
        <option value="javascript" />
        <option value="C#" />
        <option value="python" />
    </datalist>
</form>

Output:

input attributes Aya Bouchiha

Summary:

pattern: specifies a valid JavaScript regular expression that the input field's value is checked against.

maxlength: specifies the maximum length of characters allowed in an input field.

autocomplete: specifies that the browser can display options to fill in the field when a user starts typing or not.

autofocus: specifies that an input field should automatically get focus when the page loads or not

list: used to display a list of pre-defined options for an element to suggest the user.

Reference

for contacting me

Happy codding!


This content originally appeared on DEV Community and was authored by Aya Bouchiha


Print Share Comment Cite Upload Translate Updates
APA

Aya Bouchiha | Sciencx (2021-07-16T00:39:05+00:00) 5 useful Input Attributes. Retrieved from https://www.scien.cx/2021/07/16/5-useful-input-attributes/

MLA
" » 5 useful Input Attributes." Aya Bouchiha | Sciencx - Friday July 16, 2021, https://www.scien.cx/2021/07/16/5-useful-input-attributes/
HARVARD
Aya Bouchiha | Sciencx Friday July 16, 2021 » 5 useful Input Attributes., viewed ,<https://www.scien.cx/2021/07/16/5-useful-input-attributes/>
VANCOUVER
Aya Bouchiha | Sciencx - » 5 useful Input Attributes. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/07/16/5-useful-input-attributes/
CHICAGO
" » 5 useful Input Attributes." Aya Bouchiha | Sciencx - Accessed . https://www.scien.cx/2021/07/16/5-useful-input-attributes/
IEEE
" » 5 useful Input Attributes." Aya Bouchiha | Sciencx [Online]. Available: https://www.scien.cx/2021/07/16/5-useful-input-attributes/. [Accessed: ]
rf:citation
» 5 useful Input Attributes | Aya Bouchiha | Sciencx | https://www.scien.cx/2021/07/16/5-useful-input-attributes/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.