|
From: <sv...@de...> - 2005-06-01 14:20:30
|
Author: pcamacho
Date: 2005-06-01 10:20:17 -0400 (Wed, 01 Jun 2005)
New Revision: 1226
Modified:
humano2/trunk/web/portal/site/js/inputstocheck.js
humano2/trunk/web/portal/site/xsl/RUT.xsl
Log:
FIX:=20
* bug in email
* validation of RUT
Modified: humano2/trunk/web/portal/site/js/inputstocheck.js
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- humano2/trunk/web/portal/site/js/inputstocheck.js 2005-05-31 22:44:23=
UTC (rev 1225)
+++ humano2/trunk/web/portal/site/js/inputstocheck.js 2005-06-01 14:20:17=
UTC (rev 1226)
@@ -1,3 +1,63 @@
+/// Mail functions ///
+function isValidEmail(email, required) {
+ if (required=3D=3Dundefined) { // if not specified, assume it's re=
quired
+ required=3Dtrue;
+ }
+ if (email=3D=3Dnull) {
+ if (required) {
+ return false;
+ }
+ return true;
+ }
+ =20
+ if (email.length=3D=3D0) {
+ if (required) {
+ return false;
+ }
+ return true;
+ }
+ if (! allValidChars(email)) { // check to make sure all characters =
are valid
+ return false;
+ }
+ if (email.indexOf("@") < 1) { // must contain @, and it must not be=
the first character
+ return false;
+ } else if (email.lastIndexOf(".") <=3D email.indexOf("@")) { // las=
t dot must be after the @
+ return false;
+ } else if (email.indexOf("@") =3D=3D email.length) { // @ must not =
be the last character
+ return false;
+ }
+=09
+ return true;
+}
+
+
+function verifyEmail(value)=20
+{
+ var checkEmail =3D value
+ var mailOk =3D true;
+ if (isValidEmail(checkEmail,false) =3D=3D false)
+ {
+ alert("You have entered an invalid email address( " + checkEmail=
+ "). Please try again.");
+ mailOk =3D false; =20
+ }
+ return mailOk;
+}
+
+function allValidChars(email) {
+ var parsed =3D true;
+ var validchars =3D "abcdefghijklmnopqrstuvwxyz0123456789@.-";
+ for (var i=3D0; i < email.length; i++) {
+ var letter =3D email.charAt(i).toLowerCase();
+ if (validchars.indexOf(letter) !=3D -1)
+ continue;
+ parsed =3D false;
+ break;
+ }
+ return parsed;
+}
+
+/// Decimals function ///
+
function checkDecimals(fieldValue,decallowed,min,max)=20
{=09
var decimalsOk =3D true;
@@ -37,37 +97,89 @@
}
=20
=20
-function verifyEmail(value)=20
+/// RUT Validation ///
+ =20
+/**
+ * To validate the rut given the base and the check digit (digito verifi=
cador)
+ * @param rut everything minus the check digit and the separator charact=
er
+ * @param dv the check digit
+ * @return true if the rut fits with dv , false otherwise
+ */ =20
+function validaM11(rut, dv)=20
{
- var checkEmail =3D value
- var mailOk =3D true;
+ var suma =3D 0;
+ var mul =3D 2;
+ var i =3D 0;
+ for (i =3D rut.length-1; i >=3D 0; i--)=20
+ {
+ suma =3D suma + rut.charAt(i) * mul;
+ mul =3D mul=3D=3D7 ? 2 : mul+1;
+ }
+ var dvr =3D '' + (11 - suma % 11);
+ if (dvr =3D=3D '10')
+ dvr =3D 'K';
+ else if (dvr=3D=3D'11')
+ dvr =3D '0';
+ if (dvr !=3D dv)
+ return false;
+ else
+ return true;
+} =20
+
+/**
+ * Takes a string and removes all instances of characters passed in para=
m
+ * @param str the string to clean
+ * @param car the car to remove
+ * @return the string str without all instances of car
+ */
+function Clean(str,car)
+{
+ var res =3D"";
=20
- if (isValidEmail(checkEmail,true) =3D=3D true)
+ for(i=3D0;i<str.length;i++)
{
- =20
- }else{
- alert("You have entered an invalid email address( " + checkEmail=
+ "). Please try again.");
- mailOk =3D false; =20
+ if(str[i] !=3D car) =20
+ {
+ res +=3D str[i];
+ }
}
+ return res; =20
+}
+
+
+/**
+ * Says if a rut is valid or not
+ * @param rutStr something like 21557952-2 or 21.557.952-2 etc...
+ * @return true if the rut is valid, false otherwise
+ */
+function checkRut(rutStr)
+{
+ var rutOk =3D true;
+ //Delete all possible separator caracters
+ var carSepArr =3D new Array('.','-',' ','/');
+ var i=3D0;
+ var rutClean =3D rutStr
=20
-/* =20
- if(checkEmail =3D=3D '' || checkEmail =3D=3D null)
+ =20
+ for(i=3D0;i<carSepArr.length;i++)
{
- return true;
+ rutClean =3D Clean(rutClean,carSepArr[i]);
}
=20
- if ( (checkEmail.indexOf('@') < 0)=20
- ||=20
- ((checkEmail.charAt(checkEmail.length-4) !=3D '.') && (check=
Email.charAt(checkEmail.length-3) !=3D'.'))
- ) =09
+ var rut =3D rutClean.substring(0,rutClean.length-1);
+ var verif =3D rutClean[rutClean.length-1];
+ //alert(rut);
+ //alert(verif);
+ rutOk =3D validaM11(rut,verif);
+ =20
+ if(rutOk =3D=3D false)
{
- alert("You have entered an invalid email address( " + checkEmail=
+ "). Please try again.");
- mailOk =3D false;
- }=09
- */ =20
- return mailOk;
+ alert("The RUT " + rutStr + " is not valid.") =20
+ }
+ =20
+ return rutOk;
}
- =20
+ =20
function checkIsObligatory(isObligatory,value)
{
var isObligatoryOk =3D true;
@@ -117,6 +229,9 @@
case 'EMAIL':
checkOk =3D verifyEmail(this.value);
break;
+ case 'RUT':
+ checkOk =3D checkRut(this.value);
+ break;
}
=20
return checkOk; =20
@@ -207,47 +322,4 @@
aNewInput.Check() =3D=3D false );
}
=20
-//Mail functions
=20
-function isValidEmail(email, required) {
- if (required=3D=3Dundefined) { // if not specified, assume it's re=
quired
- required=3Dtrue;
- }
- if (email=3D=3Dnull) {
- if (required) {
- return false;
- }
- return true;
- }
- if (email.length=3D=3D0) { =20
- if (required) {
- return false;
- }
- return true;
- }
- if (! allValidChars(email)) { // check to make sure all characters =
are valid
- return false;
- }
- if (email.indexOf("@") < 1) { // must contain @, and it must not be=
the first character
- return false;
- } else if (email.lastIndexOf(".") <=3D email.indexOf("@")) { // las=
t dot must be after the @
- return false;
- } else if (email.indexOf("@") =3D=3D email.length) { // @ must not =
be the last character
- return false;
- }
-=09
- return true;
-}
-
-function allValidChars(email) {
- var parsed =3D true;
- var validchars =3D "abcdefghijklmnopqrstuvwxyz0123456789@.-";
- for (var i=3D0; i < email.length; i++) {
- var letter =3D email.charAt(i).toLowerCase();
- if (validchars.indexOf(letter) !=3D -1)
- continue;
- parsed =3D false;
- break;
- }
- return parsed;
-}
Modified: humano2/trunk/web/portal/site/xsl/RUT.xsl
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- humano2/trunk/web/portal/site/xsl/RUT.xsl 2005-05-31 22:44:23 UTC (re=
v 1225)
+++ humano2/trunk/web/portal/site/xsl/RUT.xsl 2005-06-01 14:20:17 UTC (re=
v 1226)
@@ -30,7 +30,7 @@
=20
<xsl:if test=3D"/page/flagaction!=3D'Read'"> <!-- Only for creat=
e and update -->
<script language=3D"Javascript">
- var aInputToCheck =3D new InputToCheck('TEXT',''); //By =
default, does no verification
+ var aInputToCheck =3D new InputToCheck('RUT',''); //RUT =
verification
allInputsToCheck.Add(aInputToCheck);
</script>
</xsl:if>
|