﻿function HasText(str) {
    return /\S+/.test(str);
}

function IsValidEmail(data) {
    return /^[a-z|A-Z|0-9|]+(([_][a-z|A-Z|0-9]*)*([-][a-z|A-Z|0-9]*)*([.][a-z|A-Z|0-9|_]+)*)*?@([a-z|A-Z|0-9]+([-][a-z|A-Z|0-9]+)*\.([a-z|A-Z|0-9]+([-][a-z|A-Z|0-9]+\.)*([a-z|A-Z][a-z|A-Z|0-9]*)?))+$/.test(data);
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


var r = {
    'alphanumeric': /[^α-ωΑ-Ωa-zA-Z0-9άέήίόύώΆΈΉΊΌΎΏ ]/g, //for alphanumeric
    'email': /[^α-ωΑ-Ωa-zA-Z0-9_@άέήίόύώΆΈΉΊΌΎΏ.]/g,      //for email
    'string': /[^α-ωΑ-Ωa-zA-ZάέήίόύώΆΈΉΊΌΎΏ ]/g,          //for strings only
    'quotes': /['\''&'\"']/g,                             //no quotes allowed
    'numbers': /[^\d]/g,                                  //show only numbers
    'notnumbers': /[^\D]/g,                              //dont show numbers
    'folderchars': /[^α-ωΑ-Ωa-zA-Z0-9άέήίόύώΆΈΉΊΌΎΏ!@#$%^&():_\\]/g  //no disallowed folder characters
}
function InvalidField(fieldName, validationType) {
    return (r[validationType].test(fieldName.value) == true);
}
function ReplaceFieldKeyType(o, w) {
    o.value = o.value.replace(r[w], '');
    //o.value = o.value.toUpperCase();
    //o.value = o.value.replace('Ά','Α');
    //o.value = o.value.replace('Έ','Ε');
    //o.value = o.value.replace('Ή','Η');
    //o.value = o.value.replace('Ί','Ι');
    //o.value = o.value.replace('Ό','Ο');
    //o.value = o.value.replace('Ύ','Υ');
    //o.value = o.value.replace('Ώ','Ω');
    //o.value = o.value.replace('ς','Σ');
}
