Hybrid View

  1. #1
    Sencha User
    Join Date
    Apr 2012
    Posts
    36
    Vote Rating
    -2
    arpit2438735 is an unknown quantity at this point

      0  

    Default 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?

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,604
    Answers
    3450
    Vote Rating
    818
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    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)

    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();
            }
        }
    });
    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().
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Apr 2012
    Posts
    36
    Vote Rating
    -2
    arpit2438735 is an unknown quantity at this point

      0  

    Default


    Thanks for Help.Where to add as I have code like this
    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
    }
    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.

Thread Participants: 1

Tags for this Thread