﻿function ValidateNumeric(source, arguments)
{
    var Regxp = /[^0-9]/;
    
    if (Regxp.test(arguments.Value) || arguments.Value.length == 0)
    {
        arguments.IsValid = false;
    }
    else
    {
        arguments.IsValid = true;
    }
}

function ValidateAlphaNumeric(source, arguments)
{
    var Regxp = /[^0-9A-Za-z\s]/;
    
    if (Regxp.test(arguments.Value))
    {
        arguments.IsValid = false;
    }
    else
    {
        arguments.IsValid = true;
    }
}

function ValidateZip(source, arguments)
{
    var Regxp = /^\d{5}([\-]\d{4})?$/;
    
    if (Regxp.test(arguments.Value))
    {
        arguments.IsValid = true;
    }
    else
    {
        arguments.IsValid = false;
    }   
}

function ValidateBirthDate(source, arguments)
{
    var Regxp = /(0[1-9]|1[012])[/](0[1-9]|[12][0-9]|3[01])[/](19|20)\d\d/;
    var now = new Date();
    
    if (Regxp.test(arguments.Value))
    {
        if (Date.parse(now.getMonth() + 1 + '/' + now.getDate() + '/' + now.getFullYear()) > Date.parse(arguments.Value))
        {
            arguments.IsValid = true;
        }
        else
        {
            arguments.IsValid = false;
        }
    }
    else
    {
        arguments.IsValid = false;
    }   
}

function ValiDate(source, arguments)
{
    var dateStr = arguments.Value;
    
    if (dateStr.length < 3) 
    {
        arguments.isValid = true;
        return;
    }
    
    var bRet = false;
    var datePat = /^(\d{2})(\/|-)(\d{2})(\/|-)(\d{4})$/;   
    var matchArray = dateStr.match(datePat); // is the format ok?    

    if (matchArray == null) 
    {
        arguments.IsValid = false;
        return;
    }

    month = matchArray[1]; // p@rse date into variables
    day = matchArray[3];
    year = matchArray[5];

    if (month < 1 || month > 12) 
    {   // check month range
        arguments.IsValid = false;
        return;
    }

    if (day < 1 || day > 31)
    {
        arguments.IsValid = false;
        return;
    }

    if ((month==4 || month==6 || month==9 || month==11) && day==31) 
    {
        arguments.IsValid = false;
        return;
    }
    
    if (month == 2)
    { // check for february 29th
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day > 29 || (day==29 && !isleap))
        {
            arguments.IsValid = false;
            return;
        }
    }
    arguments.IsValid = true;
    return;
}

