codice:
Validation.add('IsEmpty', '', function(v) {
return ((v == null) || (v.length == 0)); // || /^\s+$/.test(v));
});
Validation.addAllThese([
['required', 'Questo é un campo obbligatorio.', function(v) {
return !Validation.get('IsEmpty').test(v);
}],
['validate-number', 'Inserisci un numero valido.', function(v) {
return Validation.get('IsEmpty').test(v) || (!isNaN(v) && !/^\s+$/.test(v));
}],
['validate-digits', 'Usa solo numeri in questo campo. Non inserire spazi, punti o virgole.', function(v) {
return Validation.get('IsEmpty').test(v) || !/[^\d]/.test(v);
}],
['validate-alpha', 'Usa solo lettere (a-z).', function (v) {
return Validation.get('IsEmpty').test(v) || /^[a-zA-Z]+$/.test(v);
}],
['validate-alphanum', 'Usa solo lettere (a-z) o numeri (0-9). Nessun altro carattere é permesso.', function(v) {
return Validation.get('IsEmpty').test(v) || !/\W/.test(v);
}],
['validate-date', 'Inserisci una data valida.', function(v) {
var test = new Date(v);
return Validation.get('IsEmpty').test(v) || !isNaN(test);
}],
['validate-email', 'Inserisci una email valida. Per esempio fred@domain.com .', function (v) {
return Validation.get('IsEmpty').test(v) || /\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(v)
}],
['validate-url', 'Inserisci un URL valido.', function (v) {
return Validation.get('IsEmpty').test(v) || /^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i.test(v)
}],
['validate-date-au', 'Usa questa formattazione di data: dd/mm/yyyy. Per esempi 17/03/2009 per il 17 di Marzo, 2009.', function(v) {
if(Validation.get('IsEmpty').test(v)) return true;
var regex = /^(\d{2})\/(\d{2})\/(\d{4})$/;
if(!regex.test(v)) return false;
var d = new Date(v.replace(regex, '$2/$1/$3'));
return ( parseInt(RegExp.$2, 10) == (1+d.getMonth()) ) &&
(parseInt(RegExp.$1, 10) == d.getDate()) &&
(parseInt(RegExp.$3, 10) == d.getFullYear() );
}],
['validate-currency-dollar', 'Inserisci un valore in $ valido. Per esempio $100.00 .', function(v) {
// [$]1[##][,###]+[.##]
// [$]1###+[.##]
// [$]0.##
// [$].##
return Validation.get('IsEmpty').test(v) || /^\$?\-?([1-9]{1}[0-9]{0,2}(\,[0-9]{3})*(\.[0-9]{0,2})?|[1-9]{1}\d*(\.[0-9]{0,2})?|0(\.[0-9]{0,2})?|(\.[0-9]{1,2})?)$/.test(v)
}],
['validate-selection', 'Seleziona un campo', function(v,elm){
return elm.options ? elm.selectedIndex > 0 : !Validation.get('IsEmpty').test(v);
}],
['validate-one-required', 'Seleziona una delle seguenti opzioni.', function (v,elm) {
var p = elm.parentNode;
var options = p.getElementsByTagName('INPUT');
return $A(options).any(function(elm) {
return $F(elm);
});
}]
]);
Grazie ancora