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