﻿// JScript 文件


//去掉左右空格
String.prototype.Trim = function() 
{ 
    return this.replace(/(^\s*)|(\s*$)/g, ""); 
}  

//去掉左空格
String.prototype.LTrim = function() 
{ 
    return this.replace(/(^\s*)/g, ""); 
}  

//去掉右空格
String.prototype.RTrim = function() 
{ 
    return this.replace(/(\s*$)/g, ""); 
} 

//判断邮箱
String.prototype.CheckEmail = function()
{   
    var MyNumber =  this.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/);
    if(MyNumber == -1)
        return false;
    return true;
}

//判断生日
String.prototype.CheckDate = function()
{
    var MyNumber =  this.search(/^\d{4}-\d{1,2}-\d{1,2}$/);
    
    if(MyNumber == -1)
        return false;
        
    var y = parseInt(this.split("-")[0]);
　　var m = parseInt(this.split("-")[1]);
　　var d = parseInt(this.split("-")[2]);
    
    switch(m)
    {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            if(d>31)
                return false;
            return true;
            break;
        case 2:
            if((y%4==0 && d>29) || ((y%4!=0 && d>28)))
                return false;
            return true;
            break;
        case 4:
        case 6:
        case 9:
        case 11:
            if(d>30)
                return false;
            return true;
            break;
        default:
            return false;
            break;
    }
}

//判断电话号码
String.prototype.CheckPhone = function()
{
    var MyNumber =  this.search(/^\d{3,4}-\d{7,8}(-\d{3,4})?$/);
    if(MyNumber == -1)
        return false;
    return true;
}

//判断手机号码
String.prototype.CheckMoblieNo = function()
{
    var MyNumber =  this.search(/((^[1])(3[0-9]\d{8}|5[0-9]\d{8}|6[0-9]\d{8})$)/);
    if(MyNumber == -1)
        return false;
    return true;  
}

//判断邮政编号
String.prototype.CheckPostCode = function()
{
    var MyNumber =  this.search(/^[1-9]{1}[0-9]{5}$/);
    if(MyNumber == -1)
        return false;
    return true;  
}

//判断字符的长度
String.prototype.GetStringLength = function()
{
    var MyLength = this.length;
    var Str = this;  
    var TestStr=''; 
    var TheLen=0;
    for(var i=0;i<MyLength;i++)   
    { 
        TestStr = Str.charCodeAt(i);
        if(TestStr>255)
        {
            TheLen = TheLen + 2; 
        }
        else
        { 
            TheLen = TheLen + 1;   
        }
    } 
    return TheLen;
}