System.debug('----'+numberMatch.Matches()); // It print true as string x contain only number if x contain a single char or any space then it will return false
.Thanks
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
use isNumeric string method..
String s = '123';
system.debug('Numerinc@@@@->'+s.isNumeric()); //returns true
String s = '123asd';
system.debug('Numerinc@@@@->'+s.isNumeric()); //returns false
All Answers
use isNumeric string method..
String s = '123';
system.debug('Numerinc@@@@->'+s.isNumeric()); //returns true
String s = '123asd';
system.debug('Numerinc@@@@->'+s.isNumeric()); //returns false
Hi,
I wish this code will be useful for you.
You can find a string contain only number or not by Regex.
String x = '123';
Pattern numberFormat = Pattern.Compile('[0-9]*');
Matcher numberMatch = numberFormat.matcher(x);
System.debug('----'+numberMatch.Matches()); // It print true as string x contain only number if x contain a single char or any space then it will return false
.Thanks
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
Thanks Sam