PDA

View Full Version : Need help for writing a Regular Expression using MaskRe



Jean Bombeur
2 Feb 2016, 2:16 AM
Hi,

I'm using a Ext.form.field.Text and I need to restrict the user to enter some special characters.
Here is my current code:


this.components.reference = Ext.create('Ext.form.field.Text', {
id: 'reference_o',
fieldLabel: this.translations.reference,
maxLength: 13,
enforceMaxLength: true,
selectOnFocus: true,
maskRe: /^[a-zA-Z0-9\/\-\'\?\:()\.,\+\s]+$/,
width: 250,
margin: '10 15 15 15'
});


The mask that I'm currently using is working fine but I would like to add 2 more restrictions:
User must not start or end the text with a '/'
User must not enter a text containing '//'s (anywhere in the text)
Examples:

/fhg54564DS+DSD -> invalid
hjfsiz?45ZR/ -> invalid
fsfsn:MPD//fsfsfs -> invalid
sosg46sgsg,-?ss44DGSfsfs -> valid
Does anyone can help me with this?

Thank you in advance!

Gary Schlosberg
2 Feb 2016, 5:35 AM
You should be able to accomplish that using the stripCharsRe (http://docs.sencha.com/extjs/4.2.5/#!/api/Ext.form.field.Text-cfg-stripCharsRe) config:


stripCharsRe: /^\/|\/\//,