Siebel Problem with isNAN eScript

Recently I was working with a requirement where the field needs to be validated to accept only numeric values. This requirement looked to be a simple one. Adding a validation on the PreSetFieldValue of the Business Component solved the problem.

Below is the code added

...............................
...........
if(isNaN(FieldValue){
           TheApplication().RaiseErrorText("Sorry, invalid number, please enter numbers alone.");
}

.......


Thats it....


Now when testing all looked fine until accidentally I entered 123123e. There was no error thrown and the value was accepted. How ever this is not what the code is suppose to be doing. So thought of getting in deeper, tested with 88779e no error thrown, then with 2341209d error thrown.

So "e" at the end was the killer. Some how a number ending with e is considered as a infinite number (not sure if I am correct).

As an alternative and get rid of this scenario changed the code as below and it worked like a charm.

...............................................
.................
.....
var CheckString = FieldValue;
var Pattern = /[^0=9]/g; //non numeric pattern search
var result = CheckString.match(Pattern); //Get all the values which are not numeric

//if result is not null and length of result is non zero then the string is non numeric
if( result && result.length){
              TheApplication().RaiseErrorText("Sorry, invalid number, please enter numbers alone.");
}

...................................


isNaN problem solved !!!!


Comments

Popular posts from this blog

Siebel - DeleteRecord Method in eScript

How to call a Business Service from a PM/PR file in Siebel Open UI

Siebel Business Service Part-4