﻿/**********************************************************
* Description:
*   This file contains general purpose javascript string 
*   functions.
**********************************************************/

/*********************************************************
* Description:  
*    Determines if the passed in string is a number or not.
* Returns:  
*    True if a number, False otherwise.
*********************************************************/
function isNumber(str) 
{
    return /^\-*\d*\.*\d+$/.test(str);
}

/*********************************************************
* Description:  
*    Determines if the passed in string is a 4 digit number
*    or not.
* Returns:  
*    True if a 4 digit number, False otherwise.
*********************************************************/
function isValidYear(str) 
{
    return /^(19[0-9][0-9]|20[0-6][0-9]|207[0-8])$/.test(str);
}

// This function notifies you if any non-supported 
// characters are used.
function containsInvalidChars(str)
{
    return /[][!@#%<>$&();*/\\].*/.test(str);
}

// This function notifies you if any non-supported 
// characters are used.
function containsInvalidCharsLimitedSet(str)
{
    return /[@\\].*/.test(str);
}

// This function notifies you if the string is in 
// the date format of Month Abbrev with full year.
// The calling method should tolowercase the string.
// This method should probably be called in conjunction 
// with the isDateOfAbbrevMonthFullYearWithinRange() method
// to restrict the year range.
function isDateOfAbbrevMonthFullYear(str) 
{
    return /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec) ([0-9][0-9][0-9][0-9])$/.test(str);
}

// This function notifies you if the string is in 
// the date format of Month Abbrev with full year.
// The calling method should tolowercase the string.
// It is restricted to the years of 1900 thru 2078.
function isDateOfAbbrevMonthFullYearWithinRange(str) 
{
    return /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec) (19[0-9][0-9]|20[0-6][0-9]|207[0-8])$/.test(str);
}

// This function notifies you if the string is a
// valid URL format.
function isURL(str) 
{
    return /^https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?/.test(str);
}

// This function notifies you if the string is 
// anything else except for upper and lower case 
// letters, numbers, and spaces.
function isKeyword(str)
{
    return /^[A-Za-z0-9 ]*$/.test(str);
}

// This function notifies you if the string is 
// anything else except for upper and lower case 
// letters, numbers, single quote and spaces.
function isAuthor(str)
{
    return /^[A-Za-z0-9-' ]*$/.test(str);
}
