PDA

View Full Version : How to set up regex and maskre?



v2108
25 Jul 2012, 12:23 AM
Hi guys,

i want to define a textfield where the input must look like: Firstname,Lastname - Job, DD.MM.YYYY HH:MM
How does the regex and maskre definiton look like?

Please help me, if you know :).

Nice greets, Victoria

scottmartin
25 Jul 2012, 5:16 AM
Please have a look at vtypes:
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.field.VTypes

Scott.

v2108
25 Jul 2012, 5:25 AM
I've already read this, but I still do not no how to combine this differnt things like /[A-Z]/ and date with "," or "-".

scottmartin
25 Jul 2012, 5:34 AM
Search for 'regular expressions' on internet. There are _many_ examples.

Online:
http://gskinner.com/RegExr/

There are apps like: regexbuddy

Scott.

friend
25 Jul 2012, 5:34 AM
In the long run, I think you're going to cause yourself headaches by trying to fit this many disparate kinds of data into a single field. A much better alternative would be to break out each of these data items into their own fields, where this will make each field must easier to mask/validate. This would also let you use an Ext.form.field.Date field to capture the date/time portion of your data, where you'll get the nice GUI date picker plus a lot of helpful formatting and validation options.

Breaking everything out into multiple fields will also help you on the server-side, where you'll have individual request parameters for each field and won't have to worry about parsing a delimited String and doing data conversions.

If a design requirement is forcing you to use a single field, keep in mind that the maskRe regex expression only filters out undesirable keystrokes, but won't do anything to stop a user from entering desired keystrokes in a particular order. As for the regex expression, it's only used to validate what the user has entered and won't physically stop them from putting in poorly formatted data; it just turns the field red if the data entered doesn't match the desired format.

v2108
8 Aug 2012, 2:58 AM
Thanks for your answers, I finally decided to make different fields for text, date and time.