Client validators are used in web forms to check and validate user entry in specific fields which either must respect some rules or have a format or must be converted before sending data to the server. It is mostly used to check fields like Email , credit card, password, phone number, etc...
<clientValidator id="number">
<parameter name="num.signed" value="false" />
<parameter name="num.decimal" value="0" />
<parameter name="num.negSign" value="-" />
<parameter name="num.decSign" value=",." />
<parameter name="num.sepSign" value=" " />
<filter call="f_vb.Filter_num" class="org.rcfaces.core.internal.validator.impl.NumFilter"/>
<translator call="f_vb.Translator_num"
class="org.rcfaces.core.internal.validator.impl.NumTranslator"/>
<checker call="f_vb.Checker_num" class="org.rcfaces.core.internal.validator.impl.NumChecker"/>
<formatter call="f_vb.Formatter_num" class="org.rcfaces.core.internal.validator.impl.NumFormatter" />
<converter object="f_vb.Converter_num" />
<!--
<onerror call="f_clientValidator.Error_null" />
<oncheckerror call="f_clientValidator.Error_focus" />
-->
</clientValidator>
<?xml version="1.0" encoding="UTF-8"?>
<rcfaces-config>
<repositories>
<repository>
<type>javascript</type>
<location>org/rcfaces/rcfacesformsample/js/repository.xml</location>
</repository>
</repositories>
<clientValidators>
<render-kit>
<!--
/** * Validaor CAESAR * * Caesar cipher*/
-->
<clientValidator id="CAESAR">
<parameter name="nb.shift" value="5" />
<!-- if is letter -->
<filter call="f_vb.Filter_alpha"
class="org.rcfaces.core.internal.validator.impl.AlphaFilter" />
<!-- To upper case -->
<translator call="f_vb.Translator_uppercase"
class="org.rcfaces.core.internal.validator.impl.UpperCaseTranslator" />
<!-- Caesar cipher -->
<formatter call="av_caesar.DoIt" />
</clientValidator>
</render-kit>
</clientValidators>
</rcfaces-config>
<?xml version="1.0" encoding="UTF-8"?>
<repository id="javascript" baseDirectory="org/rcfaces/rcfacesformsample/js" convertSymbols="true">
<module id="clientValidator">
<file name="av_caesar.js">
<class name="av_caesar">
</class>
</file>
</module>
</repository>
/**
* class av_caesar.
*
* @class av_caesar
* @author JBM
*
*/
var __statics = {
/**
* @method public static
* @context object:validator
*/
DoIt : function(validator, inVal) {
if (!inVal) {
validator.f_setObject(null);
return inVal;
}
k = validator.f_getIntParameter("nb.shift");
Alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ';
var clair = inVal;
while (k < 0) {
k += 26
};
while (k > 25) {
k -= 26
};
n = 0;
chiffre = "";
for ( var count = 0; count < clair.length; count++) {
var alpha = clair.charAt(count);
idx = Alphabet.indexOf(alpha);
if (idx > -1) {
if ((n % 5 == 0) && (n > 0)) {
chiffre += " ";
};
n++;
chiffre += Alphabet.charAt(idx + k);
}
}
return chiffre;
}
}
new f_class("av_caesar", {
statics : __statics
});
Finally, we create a jsp file that use the new custom validator :
<vh:javaScript requiredModules="clientValidator" />
<v:textEntry id="field clientValidator="CAESAR">
When the user type within the text field, only alpha characters are authorized. They are automatically changed to upper case as the user is typing. When the field loses focus, the Caesar cipher is called.