﻿// Created by Oleg
// http://www.regular-expressions.info/javascriptexample.html <-- a little about regex in javascript
// Gets an regex expression, and a text, and checking it
$.fn.validate = function(Regex) {
    var re = new RegExp(Regex);
    var Match = re.exec(this.val());
    
    if ((Match != null) && (this.val() == Match[0]))
    {
        return true;
    } 
    else
    {
        return false;
    }
}

// Email: "\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*"
// Telephone: "(\\d{2,3}-\\d{7})|(\\d{9,10})"
// Not empty: "^.+$"
// Passwords: "^\\w{5,16}$"
// Integers: "^\\d+$"
// Accept empty: add "*" to the end


// Allows only numbers to be entered
function noChars(e)
{
    var keynum;
    if(window.event) // IE
    {
      keynum = e.keyCode;
    }
    else if(e.which) // Netscape/Firefox/Opera
    {
      keynum = e.which;
    }
    return((keynum>=48&&keynum<=57) || (keynum==45) || (keynum==8)) // 45: "-" 8:"BackSpace"
}

// Allows only chars to be entered
function noNumbers(e)
{
    var keynum;
    if(window.event) // IE
    {
      keynum = e.keyCode;
    }
    else if(e.which) // Netscape/Firefox/Opera
    {
      keynum = e.which;
    }
    return !(keynum>=48&&keynum<=57);
}