Activity Forums Salesforce® Discussions How to check a string has only numbers?

  • Ajit

    Member
    May 24, 2016 at 9:31 am

    Hi ravi,

    You can use isNumeric() or isNumericSpace() method to find a string is number or not

    String num = '23456789;
    System.assert(num.isNumeric());

    this will check string without space

    String numSpace = '5 4 6 8';
    System.assert(numSpace.isNumericspace());

    this will include spaces also.

  • Surbhi

    Member
    May 24, 2016 at 9:38 am

    Hi Ravi,

    Below is the code for your requirement:

    String numVal = '123';
    system.debug('numVal::'+numVal.isNumeric()); // Writes "numVal::TRUE" to the debug log

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos