简体   繁体   中英

ExtJs NumberField

I am using ExtJs NumberField. The good thing is it validates that only numbers are entered. But I want a hyphen as well. How could I go about editing the javascript

  var <portlet:namespace/>issueNoField = new Ext.form.NumberField({  //This takes only numbers
             fieldLabel: 'Issue No',
             width: 120,
             displayField: 'Enter no',  
             valueField:'IssNo'
         });
var <portlet:namespace/>issueNoField = new Ext.form.TextField({  //This takes only numbers
  fieldLabel: 'Issue No',
  width: 120,
  regex: /[1-9-]*/
});

Use "baseChars" option.

     var <portlet:namespace/>issueNoField = new Ext.form.NumberField({  //This takes only numbers
         fieldLabel: 'Issue No',
         width: 120,
         displayField: 'Enter no',  
         valueField:'IssNo'
         baseChars: "0123456789-"
     });

Try the Fiddle

Its better to use the textfield and adding the maskRe attribute as

maskRe: /^[0-9 -]$/

Regex属性对我来说没有用,我使用下面的代码代替:

maskRe: /[1-9-]/,
{
xtype: 'textfield',
mask: '(999) 999-9999'
}

What I'm proposing here is that we use a text field and put a mask to it to capture only numeric values in the desires format.

You can mask it according to your needs.

For Example:

'9999999999'
'999-999-9999'

More info This will give the phone number in the format you want

Just set the allowExponential config of your numberfield to false. By default it is true and it adds 'e+-' and the decimalSeparator as valid characters.

It's true. The source check the source.

Is the hyphen merely conventional, as in a US zip code (99999-9999)? In that case, you should accept only numeric input, insert the hyphen when that position is reached, and ignore any non-numeric characters.

If they hyphen is significant, so that "12-345" and "123-45" are different inputs, then you are reading text and not a number. However, that would be an extremely unfriendly system.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM