JavaScript advanced (3) common tools (validation, General)

Source: Internet
Author: User
This article describes the detailed instance code of common JavaScript advanced (3) Tools (verification and general). For more information, see common JS tools (verification and General) // name verification.
Var checkName = function (name) {// consignee name verification (criterion: name is 2-4 characters) var regu =/^ [\ u4E00-\ u9FA5] {2, 4} $ /; var re = new RegExp (regu); if (! Re. test (name) {return false;} return true ;};
// Mobile phone number verification
var checkCellphone = function(cellPhone){var regu =  /^[S|U]((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,2,3,5-9]))\d{8}$/;var re = new RegExp(regu);if (!re.test(cellPhone)) {return false;}return true;};
// Convert the Date Format
var formatDateTime = function (date){ if(date == null){return null;}else{var y = date.getFullYear();  var m = date.getMonth() + 1;  m = m < 10 ? ('0' + m) : m;  var d = date.getDate();  d = d < 10 ? ('0' + d) : d;  var h = date.getHours();  var minute = date.getMinutes();  minute = minute < 10 ? ('0' + minute) : minute;  var second = date.getSeconds();return y + '-' + m + '-' + d +' ' + h + ':'+minute+':'+second; }};
// Get the current time in the format of YYYY-MM-DD
Var CurentTime = function () {var now = new Date (); var year = now. getFullYear (); // year var month = now. getMonth () + 1; // month var day = now. getDate (); // var clock = year + ""; if (month <10) clock + = "0"; clock + = month + ""; if (day <10) clock + = "0"; clock + = day + ""; return (clock );};
// Verify the password format
var checkPasswd = function(passwd){var myreg = /^(\w|[a-z]){6,9}$/;var re = new RegExp(myreg);if(!re.test(passwd)){    return false;}return true;};

The above is the content of common JavaScript advanced (3) Tools (verification and general). For more information, see PHP Chinese website (www.php1.cn )!

Related Article

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.