The type attribute of input in the javascript-html5 already has tel, number, email, still need to write regular expression to verify?

Source: Internet
Author: User
1. The type attribute of input in html5 already has tel, number, and email. Do I need to write regular expressions for verification? 2. In html5, a total of 13 new types of input type attributes are added. I have summarized these 13 attributes, namely, the type attributes: color (define color picker), date (set... 1. The type attribute of input in html5 already has tel, number, and email. Do I need to write regular expressions for verification?
2. In html5, a total of 13 new types of input type attributes are added. I have summarized these 13 attributes, namely, the type attributes: color (define color picker), date (defines the date Field), datetime (defines the date Field), datetime-local (defines the date Field), month (defines the month of the date field), week (defines the week of the Date Field), time (defines the hour, minute, second of the date field), e-mail (defines the text field used for the e-mail address), number (defining numeric fields with the spinner control), range (defining numeric fields with the slider control), search (defining text fields for search), tel (defining text fields for telephone numbers), url (defining text fields for URLs ).
I usually use very few websites. Do I need to write regular expressions by myself or use other tags to simulate regular expressions?
3. May I ask for your new views on the 13 types added to HTML5?

Reply content:

1. The type attribute of input in html5 already has tel, number, and email. Do I need to write regular expressions for verification?
2. In html5, a total of 13 new types of input type attributes are added. I have summarized these 13 attributes, namely, the type attributes: color (define color picker), date (defines the date Field), datetime (defines the date Field), datetime-local (defines the date Field), month (defines the month of the date field), week (defines the week of the Date Field), time (defines the hour, minute, second of the date field), e-mail (defines the text field used for the e-mail address), number (defining numeric fields with the spinner control), range (defining numeric fields with the slider control), search (defining text fields for search), tel (defining text fields for telephone numbers), url (defining text fields for URLs ).
I usually use very few websites. Do I need to write regular expressions by myself or use other tags to simulate regular expressions?
3. May I ask for your new views on the 13 types added to HTML5?

Whether the front-end verification is not performed, the backend must be verified.

These types are only convenient for the browser to display different controls, and different keyboards are called on the mobile phone, but they are essentially strings, and the format cannot be ensured when uploaded to the backend.

Front-end verification only provides a better user experience. You do not need to jump to a page like the back-end verification (AJAX does not need to jump, but still needs to transmit data), but cannot guarantee the effectiveness of data.

This need to be clarified.
typeIt cannot be used as the basis for verification,
The type field only provides the selection format for the input,
In more cases, we should say that the new type is used to adapt to the existence of mobile web apps.
For example, whentype=telWhen you open the page on your mobile phone, the phone Keyboard will appear (not a digital keyboard, the two are not the same, the phone keyboard also includes*And#)
Whentype=emailWhen@And.comSymbol's full keyboard (different configurations may vary with system implementations)
This is whypattern,
When a form submission is triggered, the browser matches the input with the pattern attribute to determine whether the input is valid.
Of course, the validity of backend verification data is beyond the scope of this issue.

PS just tried again.type=emailOrtype=urlWhen the request is triggered, even if there is nopatternWill also check the input content and prompt,type=telNo. Safari does not check all content. This is the difference between browser vendors. To maintain the consistency of browser behavior, you must addpatternAttribute

As a WEB developer, it is important to consider that the data input by the front-end users is untrusted. All backend servers that may have malicious code must be verified.

Frontend and backend verification is not optional, but required! In addition, some new features have compatibility problems in some mobile browsers!

The backend verification is not considered.The verification is still required.
For example, html5 type = email, number, and other browsers have verified you, but tel does not. I do not know whether you are a mobile phone number or landline, nor do you enter a letter in tel for verification.
In general, the missing verification is compensated according to specific requirements.

@ FunkyLover.

As for your first two questions, I think it depends on your development needs: How strict are there Requirements for the format of input values and browser compatibility?

  • If the data is only used for display (for example, some personal information of a common website) and is not compatible with earlier browsers, The Built-in validation mechanisms of these types are sufficient.

  • Otherwise, if the data is used by machines (such as automatic mail) or key information (such as the contact phone number in the intermediary website), or must be compatible with earlier browsers (HTML5 is not supported ), you need to write the front-end verification code.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.