/* 
 * @author Josh Walker
 * This contains functions that are added to object prototypes
 */

//STRING FUNCTIONS FOR FORM VALIDATION
/**
 * Tests to see if the String is in valid e-mail address format.
 * @return {boolean}    Returns true if it is in valid e-mail format, false if not.
 */
String.prototype.isEmail = function()
{
    return this.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/);
}
/**
 * Tests to see if the String is in valid street address format.
 * @return {boolean}    Returns true if it is in valid street address format, false if not.
 */
String.prototype.isAddress = function()
{
    return this.match(/^[A-Za-z0-9\ \.\#]{2,60}$/);
}
/**
 * Tests to see if the String is a valid first name.
 * @return {boolean}    Returns true if it is a valid first name, false if not.
 */
String.prototype.isFirstName = function()
{
    return this.match(/^[A-Za-z]{2,40}$/);
}
/**
 * Tests to see if the String is a valid last name.
 * @return {boolean}    Returns true if it is a valid last name, false if not.
 */
String.prototype.isLastName = function()
{
    return this.match(/^[A-Za-z]{2,40}$/);
}
/**
 * Tests to see if the String is a valid city name.
 * @return {boolean}    Returns true if it is a valid city name, false if not.
 */
String.prototype.isCity = function()
{
    return this.match(/^[A-Za-z\ \.]{2,40}$/);
}
/**
 * Tests to see if the String is a valid state name.
 * @return {boolean}    Returns true if it is a valid state name, false if not.
 */
String.prototype.isState = function()
{
    return this.match(/^[A-Za-z]{2}$/);
}
/**
 * Tests to see if the String is a valid United States zip code.
 * @return {boolean}    Returns true if it is a valid zip code, false if not.
 */
String.prototype.isZip = function()
{
    return this.match(/^[0-9]{5}$/);
}
/**
 * Tests to see if the String is a valid phone number in United States format.
 * @return {boolean}    Returns true if it is a valid phone number, false if not.
 */
String.prototype.isPhone = function()
{
    return this.match(/^\(?[0-9]{3}[-\(\)\.,]?[0-9]{3}[-\.,]?[0-9]{4}$/);
}
/**
 * Tests to see if the String is a valid username according to our site rules.
 * @return {boolean}    Returns true if it is a valid username, false if not.
 */
String.prototype.isUsername = function()
{
    return this.match(/^[A-Za-z0-9\_\-\.]{4,20}$/);
}
/**
 * Tests to see if the String is a valid password according to our site rules.
 * @return {boolean}    Returns true if it is a valid password, false if not.
 */
String.prototype.isPassword = function()
{
    return this.match(/^[A-Za-z0-9\_\-\.!@#$%^&*]{4,20}$/);
}
//end String form validation functions
