Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

How to check for numeric?

Avatar

Former Community Member
I want to check if the data entered by the user is numeric or not. Below is my code:



if (this.rawValue != null) {

if(!(IsNumeric(this.rawValue)){

xfa.host.messageBox("Please enter Numeric ID");

xfa.host.setFocus(this.somExpression);

}

}



function IsNumeric(sText){

var ValidChars = "0123456789";

var IsNumber=true;

var Char;



for (i = 0; i < sText.length && IsNumber == true; i++){

Char = sText.charAt(i);

if (ValidChars.indexOf(Char) == -1)

{

IsNumber = false;

}

}

return IsNumber;

}



The above code is not working. Help is appreciated.
2 Replies

Avatar

Former Community Member
Standard JavaScript provides the isNaN() method to do this, so:



...

if (isNaN(this.rawValue)) {

...

}



Chris

Adobe Enterprise Developer Support