﻿
// validation functions

// check if string is empty
function isEmpty(str)
{
    for(var intLoop=0; intLoop<str.length; intLoop++) {
        if(str.charAt(intLoop)!=" ") {
            return false;
        }
    }
    return true;
}

// check if string is a valid email address
function isValidEmail(myEmail)
{
	if (myEmail.match(/\w+((-\w+)|(\.\w+)|(_\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]{2,5}/)) {
		return true;
    } else {
		return false;
    }
}

// check if a string is a valid US phone number
function isPhoneNumber(s)
{
    // (123) 456-7890
    var rePhoneNumber = new RegExp(/^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/);
    if (rePhoneNumber.test(s)) {
        return true;
    }

    // 123-456-7890 or 123.456.7890
    rePhoneNumber = new RegExp(/^[1-9]\d{2}\s?[\-\.]\s?\d{3}\s?[\-\.]\s?\d{4}$/);
    if (rePhoneNumber.test(s)) {
        return true;
    }
    
    return false;
}

