Custom validation pattern

The TMT Validator was designed with extensibility in mind. That's why all the validation rules and patterns are stored inside a global JavaScript object.

For this custom validation we want to be sure the user enters a string starting with http://. Our regular expression is ^http://. The TMT Validator stores all patterns inside tmt.validator.patterns, a JavaScript object, acting as a container for both built-in and custom patterns.

So all we need to do is to add the following line of JavaScript code:

<script type="text/javascript">
tmt.validator.patterns.httpstart = new RegExp("^http://");
</script>

The XHTML code for the field looks like this:

<input type="text" name="mylink" tmt:pattern="httpstart" />

Custom Pattern
Url: (must start with http://)