Ayesha
Ayesha

Reputation: 905

Javascript validation in rows of table

I am working on ag-grid where I am validating a row. So the column name is Index and here is the validation function I am using.

 function numberValidate(params) {
        var new_number = parseFloat(params.newValue);
        if (isNaN(new_number)) {
            window.alert("Invalid value " + params.newValue + ", must be a number");
        } else {
            params.data.index= new_number;
            params.api.onNewRows();

        }
    }

If I edit a row and type any value, the variable new_number will get that value. It will check if it is numerical; if it is not, it will give a window.alert.

If its a number, it will update that row with that value.

My problem is this--> If I mention '56sfdfd', it takes 56 and updates in the row. However, it should display window.alert stating that '56sfdfd' is not a number.

Any idea how to correct this in my Javascript function above. Any inputs appreciated.

Upvotes: 0

Views: 383

Answers (1)

karaxuna
karaxuna

Reputation: 26940

Try this way:

var new_number = Number(params.newValue);

Find more about this topic here.

Upvotes: 1

Related Questions