If you're like me, regular expressions can leave you in a stupefied gaze at your monitor, so I always try to find something that is close to what I need and then modify it, rather than start from scratch.
To create our own vtype
, we need to add it to the vtype
definitions. Each definition has a value, mask, error text, and a function used for testing:
xxxVal:
This is the regular expression to match againstxxxMask:
This is the masking to restrict user inputxxxText:This
is the error message that is displayed
As soon as we figure out the regular expressions we need to use, it's fairly straight forward creating our own vType
—so lets try one out. Here is a validation for our director's name field. The regular expression matches a pair of alpha strings, separated by a space, and each starting with a capital letter. Sounds like a good way to validate a name—right?
Ext.form.VTypes['nameVal'] = /^[A-Z][A-Za-z\-]+...