var checkName = function(name) { // 收货人姓名校验(准则:姓名为2-4汉字) var regu = /^[\u4E00-\u9FA5]{2,4}$/; var re = new RegExp(regu); if (!re.test(name)) { return false; } return true; };
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; };
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; } };
var CurentTime = function() { var now = new Date(); var year = now.getFullYear(); //年 var month = now.getMonth() + 1; //月 var day = now.getDate(); //日 var clock = year + ""; if(month < 10) clock += "0"; clock += month + ""; if(day < 10) clock += "0"; clock += day + ""; return(clock); };
var checkPasswd = function(passwd) { var myreg = /^(\w|[a-z]){6,9}$/; var re = new RegExp(myreg); if(!re.test(passwd)) { return false; } return true; };
以上就是JavaScript进阶(三)常见工具(校验、通用)的内容,更多相关内容请关注PHP中文网(www.php.cn)!