You can validate an ID’s length, be it 15 or 18 by using this method. This method will validate possible characters existing with an ID using regular expressions.
Are you interested in learning Salesforce from scratch! Have a look at this interesting video on Salesforce provided by Intellipaat:
static public String validateId(String Idparam) {
String id = String.escapeSingleQuotes(Idparam);
if((id.length() == 15 || id.length() == 18) && Pattern.matches('^[a-zA-Z0-9]*$', id))
return id;
}
return null;
}
Go for this in-depth job-oriented salesforce training online now!