Last active
March 7, 2022 15:03
-
-
Save bienvenuelisis/c63a1f66b43a851eb4639a5b51897b0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String? validateIntValue( | |
String value, | |
String errorMsg, { | |
bool positive = false, | |
int maxValue = 9223372036854775807, | |
}) { | |
if (value.isEmpty) { | |
return errorMsg; | |
} else { | |
try { | |
int i = int.parse(value); | |
if (i > maxValue) { | |
return errorMsg; | |
} | |
if (positive && i < 0) { | |
return errorMsg; | |
} | |
return null; | |
} catch (e) { | |
return errorMsg; | |
} | |
} | |
} | |
String? validateDoubleValue( | |
String value, | |
String errorMsg, { | |
bool positive = false, | |
double? maxValue = double.maxFinite, | |
}) { | |
if (value.isEmpty) { | |
return errorMsg; | |
} else { | |
try { | |
value = value.replaceFirst(",", "."); | |
double d = double.parse(value); | |
if (maxValue != null && d > maxValue) { | |
return errorMsg; | |
} | |
if (positive && d < 0) { | |
return errorMsg; | |
} | |
return null; | |
} catch (e) { | |
return errorMsg; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment