JS Regular Form Verification Summary, email verification, date validation, phone number verification, URL verification, credit card verification, QQ verification

Source: Internet
Author: User

This article summarizes a variety of regular verification, many are reproduced, I will try to verify the accuracy, if there are errors welcome message

The trim () method is incompatible in some browsers and it is best to rewrite the   string.prototype.trim=function () {           return This.replace (/(^\s*) | ( \s*$)/g, "");        }
Determines whether the input content is null    function IsNull () {        var str = document.getElementById (' str '). Value.trim ();        if (str.length==0) {            alert (' Sorry, the text box cannot be empty or is a space! '); /Please change the text box to the name of the property you need to verify!}    
Determines whether the date type is of type YYYY-MM-DD format    function IsDate () {         var str = document.getElementById (' str '). Value.trim ();        if (str.length!=0) {            var reg =/^ (\d{1,4}) (-|\/) (\d{1,2}) \2 (\d{1,2}) $/;     
var reg =/^ (18|19|20) \d{2} (-|\/) (\d{1,2}) \2 (\d{1,2}) &/g; You can use this method var r = Str.match (reg) to verify the exact point of the year. if (r==null) alert (' Sorry, you have entered an incorrect date format! ');//Please change the "date" to the name of the property you need to verify!}
Determines whether the date type is YYYY-MM-DD hh:mm:ss format type    function Isdatetime () {         var str = document.getElementById (' str '). Value.trim ();        if (str.length!=0) {              var reg =/^ (18|19|20) \d{2} (-|\/) (\d{1,2}) \2 (\d{2}) (\d{1,2}):(\d{1,2}):(\d{1,2}) $/g;          var r = Str.match (reg);             if (r==null)            alert (' Sorry, you have entered an incorrect date format! ');//Please change the "date" to the name of the property you need to verify!}         

JS Regular Form Verification Summary, mailbox verification, date validation, phone number verification, URL verification, credit card verification, QQ authentication

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.