isValidOTP static method
Validates if the input is a valid numeric OTP of specified length
Implementation
static String? isValidOTP(String? otp, {int length = 6}) {
if (otp == null || otp.isEmpty) {
return 'Please enter the verification code.';
}
if (otp.length != length) {
return 'Code must be $length digits.';
}
final numericRegExp = RegExp(r'^\d+$');
if (!numericRegExp.hasMatch(otp)) {
return 'Code must contain only numbers.';
}
return null;
}