cancel
Showing results for 
Search instead for 
Did you mean: 

TextField only numeric characters

b_deterd2
Active Contributor
0 Kudos

Hello All,

I'm looking for a control like TextField in which I can anly enter numeric values (0123456789).

It does not seem the TextField control is able to do that.

Has anyone encountered this problem and has a solution? Or extended the TextField already for this purpose?

Any help will be appreciated.

regards,

Bert

Accepted Solutions (1)

Accepted Solutions (1)

SandipAgarwalla
Active Contributor
0 Kudos

Bert

One option would be to use the inbuilt functions of jQuery to check if the text field value is number or not. You can also use a expression to check if the field is numeric..

I used a in-built function, and it works decently

var oTextField = new sap.ui.commons.TextField({

                              id : "id", // sap.ui.core.ID

                              value : "", // string

                              required : true, // boolean

                              width : undefined, // sap.ui.core.CSSSize

                              maxLength : 10, // int

                              textAlign : sap.ui.core.TextAlign.Begin, // sap.ui.core.TextAlign

                              change : [ function(oEvent) {

                                        //var control = oEvent.getSource();

                                        var oID = oTextField.getValue();

                                        if(isNaN(oID)){

                                                  alert("Not a number");

                                                  oTextField.setValueState(sap.ui.core.ValueState.Error);

                                        }else{

                                                  alert("its a number");

                                        }

                              }]

                    });

Answers (0)