function trim(s) 
{
var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
return (m == null) ? "" : m[1];
}


function regular_expression_validator(value,re) 
{
 value=trim(value);
 if (value.length == 0)
 return true;
 var rx = new RegExp(re);
 var matches = rx.exec(value);
 return (matches != null && value == matches[0]);
}