regular expression to accept only integers and decimal numbers

extjs, regex

Solution

- Use \d* instead of \d+ before the decimal to match zero or more digits.

- Also add anchors (^ and $) or else it will pass as long as there is any match available.

- This would also validate an empty string, so if necessary you can use a lookahead to make sure there is at least one digit:

Use Below code:

 {
         xtype: 'textfield',
         id: 'myField',
         fieldLabel: 'Text Field(numbers-only)',                      
         maskRe: /^[1-9]\d*(\.\d+)?$/

}

Per your Understanding purpose see this link Click Here

Problem

Iam working with ext js.I have a textfield that should accept either an integer or a decimal number. Iam using regular expression to implement that. But its not working. Here is my code... ``` { xtype: 'textfield', id: 'myField', fieldLabel: 'Text Field(numbers-only)', maskRe: /[0-9]+(\.[0-9]+)?$/ } ``` While using the above regular expression, Textfield is not accepting .(dot) How can I resolve this??

Original source