TMT Validator was designed with extensibility in mind. There will always be the need for custom validation. TMT Validator stores all rules inside tmt.validator.rules, a JavaScript object, acting as a container for both built-in and custom validation rules.
In order to invoke the custom validation rule, we need to add a custom attribute to the field that exactly matches the name of the custom validation. Then the validator will call our custom method passing the field's DOM node as an argument and expecting a boolean as return value:
<script type="text/javascript">
// This will be triggered by the tmt:lowercase attribute
tmt.validator.rules.lowercase = function(fieldNode){
var lowerStr = fieldNode.value.toLowerCase();
return (lowerStr == fieldNode.value);
}
</script>
The XHTML code for the field looks like this:
<input type="text" name="mylowercase" tmt:lowercase="true" tmt:message="Please enter only lowercase letters" />