| by Arround The Web | No comments

HTML- HTML5 Email Validation

Form validation is essential for preventing online forms misused by unauthorized users. Inappropriate validation of form data is one of the main reasons for the security problem. It exposes the website to header fixes, cross-site scripting, and SQL booster attacks. More specifically, Email validation is a procedure for determining whether a particular email address is active and reachable.

This post will explain the different methods for HTML5 Email Validation:

Method 1: Email Validation by Defining the Pattern in Input Element

For the HTML5 email Validation, create a form using the “<form>” element and add an input element and specify the input type as “email”, and define the pattern of the email.

Step 1: Create a Form

For the purpose of designing a form, utilize the “<form>” element in the HTML page.

Step 2: Insert Label

Next, add the “<label>” element for defining the label in the form. Then, embed text between the label tag to display on the webpage.

Step 3: Add Input Element

After that, insert an “<input>” element to create an input field and add the following attributes in the input element:

  • type” attribute determines the input type in the form. In this scenario, the value of the “type” attribute is specified as “email”, which allows the user to enter only email data in the input field.
  • pattern” specifies a regular expression that the “<input>” element’s value is checked against on form submission.
  • placeholder” allocates a short hint that describes the expected value of an input field or textarea:
<form>
 <label> Add Your Email</label>
 <input type="email" pattern="[^ @]*@[^ @]*" placeholder="Add Your Email">
 <input type="Button" value="Enter">
</form>

As a result, the user can add email in the input field:

However, if the users try to enter an invalid email, then the form will not submit:

Method 2: Email Validation by input “type” as Email

User can also add the email by specifying the input type as “email”, that support only the data that consist of email address:

<form>
 <label> Add Your Email</label>
 <input type="email" placeholder="Place Your Email Here">
 <input type="submit" value="Submit">
</form>

Output

That’s all about the HTML5 email validation methods.

Conclusion

For the HTML5 email validation, first, design a form using the “<form>” element and add an “<input>” element and specify the input “type” as “email”, and define the “pattern” by specifying a particular pattern of the email. On the other hand, the user cannot enter the other type of data in the stated field. This tutorial demonstrated the HTML5 email validation methods.

Share Button

Source: linuxhint.com

Leave a Reply