Files
alfresco-community-repo/source/web/scripts/validation.js
Gavin Cornwell b620d62954 - fixed illegal character use in forum article names
- fixed navigation issue with editing rules
- added links to details pages in forums area
- you can no longer create spaces, forums or topics with illegal characters in the name

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2745 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2006-05-03 15:28:20 +00:00

125 lines
2.9 KiB
JavaScript

//
// Validation functions
// Gavin Cornwell 30-11-2005
//
/**
* Informs the user of the given 'message', if 'showMessage' is true.
* If 'showMessage' is true focus is given to the 'control'.
*/
function informUser(control, message, showMessage)
{
if (showMessage)
{
alert(message);
control.focus();
}
}
/**
* Ensures the value of the 'control' is not null or 0.
*
* @return true if the mandatory validation passed
*/
function validateMandatory(control, message, showMessage)
{
var result = true;
if (control.value == null || control.value.length == 0)
{
informUser(control, message, showMessage);
result = false;
}
return result;
}
/**
* Ensures the value of the 'control' is more than 'min' and less than 'max'.
*
* @return true if the number range validation passed
*/
function validateNumberRange(control, min, max, message, showMessage)
{
var result = true;
if (isNaN(control.value) || control.value < min || control.value > max)
{
informUser(control, message, showMessage);
result = false;
}
return result;
}
/**
* Ensures the value of the 'control' has a string length more than 'min' and less than 'max'.
*
* @return true if the string length validation passed
*/
function validateStringLength(control, min, max, message, showMessage)
{
var result = true;
if (control.value.length < min || control.value.length > max)
{
informUser(control, message, showMessage);
result = false;
}
return result;
}
/**
* Ensures the value of the 'control' matches the 'expression' if 'requiresMatch' is true.
* Ensures the value of the 'control' does not match the 'expression' if 'requiresMatch' is false.
*
* @return true if the regex validation passed
*/
function validateRegex(control, expression, requiresMatch, matchMessage, noMatchMessage, showMessage)
{
var result = true;
/*
var pattern = new RegExp(unescape(expression));
var matches = pattern.test(control.value);
if (matches != requiresMatch)
{
if (requiresMatch)
{
informUser(control, noMatchMessage, showMessage);
}
else
{
informUser(control, matchMessage, showMessage);
}
result = false;
}
*/
return result;
}
/**
* Ensures the value of the 'control' does not contain any illegal characters.
*
* @return true if the file name is valid
*/
function validateName(control, message, showMessage)
{
var result = true;
var pattern = /[\"\*\\\>\<\?\/\:\|\%\&\+\;\xA3\xAC]+/;
var idx = control.value.search(pattern);
if (idx != -1)
{
informUser(control, control.value.charAt(idx) + " " + message, showMessage);
result = false;
}
return result;
}