-
29 May 2012 9:46 PM #1
Unanswered: Add Similar Regexp function or Similar in Sencha
Unanswered: Add Similar Regexp function or Similar in Sencha
I want to add Regexp or similar functionality just like in jquery or PHP to enter only HTTP or number only in textfield of Sencha mean to show error if user doesn't satisfy condition of any Regexp function.How can I implement it?
-
31 May 2012 11:30 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,714
- Vote Rating
- 438
- Answers
- 3113
You can listen to the keydown event and check against regexp. If it fails stopEvent() on the event object.
This is a pattern text field that takes a pattern attribute value (HTML5 pattern attrib)
That only allows numbers and keys like delete. In the onKeyDown you can use a RegExp test and if it fails then do the e.stopEvent().Code:Ext.define('Ux.field.PatternText', { extend : 'Ext.field.Text', xtype : 'patterntextfield', config : { pattern : '[0-9]*' }, updatePattern : function(pattern) { var component = this.getComponent(); component.updateFieldAttribute('pattern', pattern); }, initialize : function() { this.callParent(); var component = this.getComponent(); component.input.on({ scope : this, keydown : 'onKeyDown' }); }, onKeyDown : function(e) { var code = e.browserEvent.keyCode; if (!(code >= 48 && code <= 57) && !(code >= 97 && code <= 105) && code !== 46 && code !== 8) { e.stopEvent(); } } });Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
31 May 2012 7:14 PM #3
Thanks for Help.Where to add as I have code like this
And I also want to add max and min value ie 3 and 1 as number field didn't support.Same for adding only links Regexp function or matcher something.Code:Ext.define("PlayListApp.view.PlayEditor", { extend: "Ext.form.Panel", requires: "Ext.form.FieldSet", alias: "widget.playeditorview", config:{ scrollable: 'vertical', items: [ { xtype: 'textfield', name: 'duration', label: 'Duration', placeHolder:'99', required:true }


Reply With Quote