views:

1809

answers:

2

Hello everyone,

I am using Extjs Ext.form.FormPanel to create a form that will contain some fields like name, company,...,etc. Among the fields will be zip code and phone number, let's take the zip code problem, the zip code could be 5 numbers or 5 numbers plus 4 characters, I don't want to create two separate fields for the zip code, is there a way that I could create one field and prevent users from entering the zip code wrongly, just as the following jQuery plugin does:

http://digitalbush.com/projects/masked-input-plugin/

+1  A: 

ExtJS has vtypes, that let you write validation code.

Simpler: TextFields have a regex configuration option that forces match on validation. Your regex can be (assuming space separator then a-z only, case-insensitive):

/^\d{5}(? [a-z]{4})?$/i
streetpc
Ok, that is fine, but that doesn't give me masked input which is easier for users, I found an extjs plugin called Cherry http://code.google.com/p/cherryonext/ that has masked input features but the size of the plugin is about 131KBH which is big, any other alternative?
Ahmad
haven't used any, but here is one that seems to implement that with ExtJS: http://extjs.com/forum/showthread.php?t=64797Else you can use jQuery to do that on an Ext.form.TextField (use the input's id) and wrap it into a vtype.
streetpc
A: 

If your intent is to accept ZIP or ZIP+4, the regex format should be as follows:

/^\d{5}(?-\d{4})?$

The optional delimiter should be a dash, and the four "characters" should always be numbers.

richardtallent