// validator � Jan Andersen - frontGATE Solutions ApS
/*
Use input alt property as input type for regexp
Add id to all form elements
Use input title property as error help text
*/
var text = /(\w+)/i;
var date = /^\d{1,2}-\d{1,2}-\d{4,4}$/;
var rx_search = /(\w+)/i;
var subject = /(\w+)/i;
var name = /(\w+)\s(\w+)/i;
var address = /(\w+)/i;
var company = /(\w+)/i;
var postnr = /^\d{4}$/;
var postnrint = /\d{2,8}/;
var zip = /^\d{3,4}$/;
var city = /(\w+)/i;
var phone = /^\d{8}$/;
var intphone = /^\d{8,14}$/;
var tlf = /^\d{8}$/;
var cvr = /^\d{8}$/;
var ean = /^\d{13}$/;
var integer_syntax_valid = /^(\d+)$/;
var integer_syntax_invalidated = /(\D+)/i;
var space = /(\s+)/i;
var email_syntax_invalidated = /([\_|\-|\.|\@])([\_|\-|\.|\@])/i;
var email_syntax_valid = /^([a-z0-9])([a-z0-9|\_|\-|\.])*([a-z0-9])(\@){1,1}([a-z0-9])([a-z0-9|\_|\-|\.])*([a-z0-9])(\.)([a-z]){2,4}/i;
var rx_password = /(\w+)/i;
var anychar = /(.+)/i;
var login_username = /^\w{4,50}$/i;
var login_password = /^\w{4,50}$/i;
var currency_syntax0 = /(\d+)/;
var currency_syntax1 = /(\d+)\,\d{2}/;
var currency_syntax2 = /[kr](\s)(\d+)\,\d{2}/i;
var pValue = '';
function pExists(obj, property) {
for (var i in obj) {
if ('' + i == property) {
pValue = '' + obj[i];
return '' + obj[i];
}
}
pValue = '';
return '';
}
function clsEmail() {
this.test=_vmail;
}
function _vmail(value) {
with (this) {
if (!email_syntax_valid.test(value))
return false
else {
if (!email_syntax_invalidated.test(value))
return true;
else
return false;
}
}
}
var email = new clsEmail();
function clsValuta() {
this.test=_vvaluta;
}
function _vvaluta(value) {
with (this) {
var validated = false;
if (currency_syntax0.test(value)) {
validated = true;
}
if (currency_syntax1.test(value)) {
validated = true;
}
if (currency_syntax2.test(value)) {
validated = true;
}
return validated;
}
}
var valuta = new clsValuta();
function clsInteger() {
this.test=_vinteger;
}
function _vinteger(value) {
with (this) {
var valstr = new String(value);
if (integer_syntax_valid.test(value)) {
if (integer_syntax_invalidated.test(value))
return false;
if (valstr.indexOf(',') >= 0 || valstr.indexOf('.') >= 0)
return false;
return true;
} else {
return false;
}
}
}
var integer = new clsInteger();
function clsPassword() {
this.test=_vpassword
}
function _vpassword(value) {
with (this) {
var tstr = new String(value);
if (tstr.length > 5 && tstr.length <= 50) {
if (!rx_password.test(value))
return false;
else
return true;
}
}
return false;
}
var password = new clsPassword();
function clsSearch() {
this.test=_vsearch;
}
function _vsearch(value) {
with (this) {
if (!rx_search.test(value))
return false
else {
var sstr = new String(value);
if (sstr.indexOf(" ") > 0)
if (sstr.length>3)
return true;
if (sstr.length>2)
return true;
else
return false;
}
}
}
var search = new clsSearch();
function validate_search(id) {
if (document.getElementById(id)) {
var obj = document.getElementById(id);
if (!search.test(obj.value)) {
obj.style.borderColor = 'red';
window.alert(obj.title);
obj.focus();
return false;
}
}
return true;
}
function deformvalidate(form_name, as_btn) {
var submitform = true;
var doc = document.forms[form_name];
var gotoexit = false;
for (i=0;i