mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-12630: Validation for numbers with decimal commas.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@45608 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -59,9 +59,13 @@ function validateNumberRange(control, min, max, message, showMessage)
|
|||||||
*/
|
*/
|
||||||
function validateIsNumber(control, message, showMessage)
|
function validateIsNumber(control, message, showMessage)
|
||||||
{
|
{
|
||||||
var result = true;
|
var result = true,
|
||||||
|
testValue = control.value;
|
||||||
if (isNaN(control.value))
|
|
||||||
|
// Be tolerant of numbers that contain decimal commas and/or use a dot/apostrophe/space as a thousand separator & ignore.
|
||||||
|
testValue = testValue.toString().replace(/[ '.,]/g, "");
|
||||||
|
|
||||||
|
if (isNaN(testValue))
|
||||||
{
|
{
|
||||||
informUser(control, message, showMessage);
|
informUser(control, message, showMessage);
|
||||||
result = false;
|
result = false;
|
||||||
@@ -89,7 +93,7 @@ function validateStringLength(control, min, max, message, showMessage)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures the value of the 'control' matches the 'expression' if 'requiresMatch' is true.
|
* 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.
|
* Ensures the value of the 'control' does not match the 'expression' if 'requiresMatch' is false.
|
||||||
*
|
*
|
||||||
* @return true if the regex validation passed
|
* @return true if the regex validation passed
|
||||||
@@ -201,7 +205,7 @@ function validateValue(control, pattern, message, showMessage)
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateDialog()
|
function validateDialog()
|
||||||
{
|
{
|
||||||
if (finishButtonPressed)
|
if (finishButtonPressed)
|
||||||
@@ -235,98 +239,98 @@ function validateWizard()
|
|||||||
*
|
*
|
||||||
* @param str The string to decode
|
* @param str The string to decode
|
||||||
* @return The decoded string
|
* @return The decoded string
|
||||||
*/
|
*/
|
||||||
function decode(str)
|
function decode(str)
|
||||||
{
|
{
|
||||||
var s0, i, j, s, ss, u, n, f;
|
var s0, i, j, s, ss, u, n, f;
|
||||||
|
|
||||||
s0 = ""; // decoded str
|
s0 = ""; // decoded str
|
||||||
|
|
||||||
for (i = 0; i < str.length; i++)
|
for (i = 0; i < str.length; i++)
|
||||||
{
|
{
|
||||||
// scan the source str
|
// scan the source str
|
||||||
s = str.charAt(i);
|
s = str.charAt(i);
|
||||||
|
|
||||||
if (s == "+")
|
if (s == "+")
|
||||||
{
|
{
|
||||||
// "+" should be changed to SP
|
// "+" should be changed to SP
|
||||||
s0 += " ";
|
s0 += " ";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (s != "%")
|
if (s != "%")
|
||||||
{
|
{
|
||||||
// add an unescaped char
|
// add an unescaped char
|
||||||
s0 += s;
|
s0 += s;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// escape sequence decoding
|
// escape sequence decoding
|
||||||
u = 0; // unicode of the character
|
u = 0; // unicode of the character
|
||||||
|
|
||||||
f = 1; // escape flag, zero means end of this sequence
|
f = 1; // escape flag, zero means end of this sequence
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
ss = ""; // local str to parse as int
|
ss = ""; // local str to parse as int
|
||||||
for (j = 0; j < 2; j++ )
|
for (j = 0; j < 2; j++ )
|
||||||
{
|
{
|
||||||
// get two maximum hex characters for parse
|
// get two maximum hex characters for parse
|
||||||
sss = str.charAt(++i);
|
sss = str.charAt(++i);
|
||||||
|
|
||||||
if (((sss >= "0") && (sss <= "9")) || ((sss >= "a") && (sss <= "f")) || ((sss >= "A") && (sss <= "F")))
|
if (((sss >= "0") && (sss <= "9")) || ((sss >= "a") && (sss <= "f")) || ((sss >= "A") && (sss <= "F")))
|
||||||
{
|
{
|
||||||
ss += sss; // if hex, add the hex character
|
ss += sss; // if hex, add the hex character
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// not a hex char., exit the loop
|
// not a hex char., exit the loop
|
||||||
--i;
|
--i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse the hex str as byte
|
// parse the hex str as byte
|
||||||
n = parseInt(ss, 16);
|
n = parseInt(ss, 16);
|
||||||
|
|
||||||
// single byte format
|
// single byte format
|
||||||
if (n <= 0x7f) { u = n; f = 1; }
|
if (n <= 0x7f) { u = n; f = 1; }
|
||||||
|
|
||||||
// double byte format
|
// double byte format
|
||||||
if ((n >= 0xc0) && (n <= 0xdf)) { u = n & 0x1f; f = 2; }
|
if ((n >= 0xc0) && (n <= 0xdf)) { u = n & 0x1f; f = 2; }
|
||||||
|
|
||||||
// triple byte format
|
// triple byte format
|
||||||
if ((n >= 0xe0) && (n <= 0xef)) { u = n & 0x0f; f = 3; }
|
if ((n >= 0xe0) && (n <= 0xef)) { u = n & 0x0f; f = 3; }
|
||||||
|
|
||||||
// quaternary byte format (extended)
|
// quaternary byte format (extended)
|
||||||
if ((n >= 0xf0) && (n <= 0xf7)) { u = n & 0x07; f = 4; }
|
if ((n >= 0xf0) && (n <= 0xf7)) { u = n & 0x07; f = 4; }
|
||||||
|
|
||||||
// not a first, shift and add 6 lower bits
|
// not a first, shift and add 6 lower bits
|
||||||
if ((n >= 0x80) && (n <= 0xbf)) { u = (u << 6) + (n & 0x3f); --f; }
|
if ((n >= 0x80) && (n <= 0xbf)) { u = (u << 6) + (n & 0x3f); --f; }
|
||||||
|
|
||||||
|
// end of the utf byte sequence
|
||||||
|
if (f <= 1) { break; }
|
||||||
|
|
||||||
// end of the utf byte sequence
|
|
||||||
if (f <= 1) { break; }
|
|
||||||
|
|
||||||
if (str.charAt(i + 1) == "%")
|
if (str.charAt(i + 1) == "%")
|
||||||
{
|
{
|
||||||
// test for the next shift byte
|
// test for the next shift byte
|
||||||
i++ ;
|
i++ ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// abnormal, format error
|
// abnormal, format error
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the escaped character
|
// add the escaped character
|
||||||
s0 += String.fromCharCode(u);
|
s0 += String.fromCharCode(u);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return s0;
|
return s0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user