Apex String Methods to Determine Character Types
isAlpha()
: This string method will return true, if the string contain only characters.
//Return true String s1 = 'Biswajeet'; Boolean b1 = s1.isAlpha(); System.assertEquals(true, b1); //Return false String s2 = 'Biswajeet Samal'; Boolean b2 = s2.isAlpha(); System.assertEquals(false, b2); //Return false String s3 = 'Biswajeet1234'; Boolean b3 = s3.isAlpha(); System.assertEquals(false, b3);
isAlphaSpace()
: This string method will return true, if the string contain alphabet and white spaces.
//Return true String s1 = 'Biswajeet'; Boolean b1 = s1.isAlphaSpace(); System.assertEquals(true, b1); //Return true String s2 = 'Biswajeet Samal'; Boolean b2 = s2.isAlphaSpace(); System.assertEquals(true, b2); //Return false String s3 = 'Biswajeet1234'; Boolean b3 = s3.isAlphaSpace(); System.assertEquals(false, b3);
isAlphanumeric()
: This string method will return true, if the string contain alphabet, numbers.
//Return true String s1 = 'Biswajeet'; Boolean b1 = s1.isAlphaNumeric(); System.assertEquals(true, b1); //Return true String s2 = 'Biswajeet1234'; Boolean b2 = s2.isAlphaNumeric(); System.assertEquals(true, b2); //Return false String s3 = 'Biswajeet 1234'; Boolean b3 = s3.isAlphaNumeric(); System.assertEquals(false, b3);
isAlphanumericSpace()
: This string method will return true, if the string contain alphabet, numbers and white spaces.
//Return true String s1 = 'Biswajeet Samal'; Boolean b1 = s1.isAlphanumericSpace(); System.assertEquals(true, b1); //Return true String s2 = 'Biswajeet 1234'; Boolean b2 = s2.isAlphanumericSpace(); System.assertEquals(true, b2); //Return false String s3 = 'Biswajeet $$'; Boolean b3 = s3.isAlphanumericSpace(); System.assertEquals(false, b3);
isNumeric()
: This string method will return true, if the string contain numbers only.
//Return true String s1 = '12345'; Boolean b1 = s1.isNumeric(); System.assertEquals(true, b1); //Return false String s2 = '12.22'; Boolean b2 = s2.isNumeric(); System.assertEquals(false, b2); //Return false String s3 = 'Biswajeet1234'; Boolean b3 = s3.isNumeric(); System.assertEquals(false, b3);
isNumericSpace()
: This string method will return true, if the string contain numbers with spaces.
//Return true String s1 = '1 2 3 4 5'; Boolean b1 = s1.isNumericSpace(); System.assertEquals(true, b1); //Return true String s2 = '12.22'; Boolean b2 = s2.isNumericSpace(); System.assertEquals(false, b2); //Return false String s3 = 'Biswajeet 1234'; Boolean b3 = s3.isNumericSpace(); System.assertEquals(false, b3);
isWhitespace()
: This string method will return true, if the string contain only white spaces.
//Return true String s1 = ' '; Boolean b1 = s1.isWhitespace(); System.assertEquals(true, b1); //Return true String s2 = ''; Boolean b2 = s2.isWhitespace(); System.assertEquals(true, b2); //Return false String s3 = 'BISWA 1234'; Boolean b3 = s3.isWhitespace(); System.assertEquals(false, b3);
containsWhitespace()
: This string method will return true, if the string contain white spaces.
//Return true String s1 = 'Biswajeet Samal'; Boolean b1 = s1.containsWhitespace(); System.assertEquals(true, b1); //Return true String s2 = 'Biswajeet 1234'; Boolean b2 = s2.containsWhitespace(); System.assertEquals(true, b2); //Return true String s3 = 'BISWA '; Boolean b3 = s3.containsWhitespace(); System.assertEquals(true, b3); //Return false String s4 = 'Biswajeet'; Boolean b4 = s4.containsWhitespace(); System.assertEquals(false, b4);
isAllLowerCase()
: This string method will return true, if the string contain all characters in lowercase.
//Return true String s1 = 'biswajeet'; Boolean b1 = s1.isAllLowerCase(); System.assertEquals(true, b1); //Return false String s2 = 'Biswajeet'; Boolean b2 = s2.isAllLowerCase(); System.assertEquals(false, b2);
isAllUpperCase()
: This string method will return true, if the string contain all characters in uppercase.
//Return true String s1 = 'BISWAJEET'; Boolean b1 = s1.isAllUpperCase(); System.assertEquals(true, b1); //Return false String s2 = 'Biswajeet'; Boolean b2 = s2.isAllUpperCase(); System.assertEquals(false, b2);