Home > Web Front-end > JS Tutorial > body text

JavaScript Advanced (3) Common Tools (Validation, General)

黄舟
Release: 2017-02-11 14:40:51
Original
1447 people have browsed it

JS common tools (verification, general)

// Name verification

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;
};
Copy after login

//Mobile phone number verification 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;
};
Copy after login

// Date format conversion

var formatDateTime = function (date)
{ 
if(date == null){
return null;
}else{
var y = date.getFullYear();  
var m = date.getMonth() + 1;  
m = m < 10 ? (&#39;0&#39; + m) : m;  
var d = date.getDate();  
d = d < 10 ? (&#39;0&#39; + d) : d;  
var h = date.getHours();  
var minute = date.getMinutes();  
minute = minute < 10 ? (&#39;0&#39; + minute) : minute;  
var second = date.getSeconds();
return y + &#39;-&#39; + m + &#39;-&#39; + d +&#39; &#39; + h + &#39;:&#39;+minute+&#39;:&#39;+second; 
}
};
Copy after login

// Get the current time, the format is: YYYY-MM-DD

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);   
};
Copy after login

//Verification 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;
};
Copy after login

The above are JavaScript advanced (3) common tools (verification , general) content, for more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!