﻿function CheckEmail(emailAddress) {

    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!filter.test(emailAddress)) 
        return false;
    else
        return true;
}

function CheckTelephone(telephone)
{
    if (telephone.match(/^[0-9\-\s\.\)\(]{10,}$/))
        return true;
    else
        return false;
}    
function CheckTextOnly(textVal)
{
    var filter = /^[a-zA-Z\s]{0,}$/;

    if (!filter.test(textVal)) 
        return false;
    else
        return true;
}

function CheckInvalidCharacters(textVal) 
{
    var filter = /^[<>]{0,}$/;

    if (!filter.test(textVal))
        return false;
    else
        return true;
}

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function CheckPostalCode(postalCode) {
    if (postalCode.match(/^[a-zA-Z][0-9][a-zA-Z](-|\s){0,1}[0-9][a-zA-Z][0-9]$/))
        return true;
    else
        return false;

}


