You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cloudsolutions-atoms/lib/controllers/validator/validator.dart

47 lines
1.3 KiB
Dart

class Validator {
// private constructor to avoid create class object
Validator._();
// check if string not empty and has value
static bool hasValue(String? string) {
if (string == null || string.isEmpty) return false;
return true;
}
// Return true if email is valid. Otherwise, return false
static bool isEmail(String email) {
RegExp exp = RegExp(r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+");
if (exp.hasMatch(email)) return true;
return false;
}
// Return true if phone number is valid. Otherwise, return false
static bool isPhoneNumber(String phoneNumber) {
if (phoneNumber.isEmpty) {
return false;
}
const pattern = r'^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*$';
final regExp = RegExp(pattern);
if (regExp.hasMatch(phoneNumber)) return true;
return false;
}
// Return true if password is valid. Otherwise, return false
static bool isValidPassword(String password) {
if (password.length < 6) return false;
return true;
}
// Return true if String is valid Numeric. Otherwise, return false
static bool isNumeric(String s) {
return double.tryParse(s) != null;
}
// Return true if String is valid Numeric. Otherwise, return false
static bool isInt(String value) {
return int.tryParse(value) != null;
}
}