VerificationUtils.dart 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. class VerifyUtils {
  2. static final RegExp _regexUserName =
  3. RegExp("^[\u4e00-\u9fa5a-zA-Z0-9]{2,8}\$");
  4. static final RegExp _regexEmail = RegExp("^\\w+@\\w+(\.\\w+)+\$");
  5. static final RegExp _regexPassword =
  6. RegExp("^(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9#?!@\$%^&*,]{8,16}\$");
  7. static bool isUserName(String? s) {
  8. if (s == null || s.isEmpty) {
  9. return false;
  10. }
  11. return _regexUserName.hasMatch(s);
  12. }
  13. static bool isEmail(String? s) {
  14. if (s == null || s.isEmpty) {
  15. return false;
  16. }
  17. return _regexEmail.hasMatch(s);
  18. }
  19. static bool isPassword(String? s) {
  20. if (s == null || s.isEmpty) {
  21. return false;
  22. }
  23. return _regexPassword.hasMatch(s);
  24. }
  25. static bool nowIsBetweenTime(int a, int? b) {
  26. DateTime now = DateTime.now();
  27. DateTime nowTime = DateTime(1, 1, 1, now.hour, now.minute, now.second);
  28. return a <= nowTime.millisecondsSinceEpoch &&
  29. nowTime.millisecondsSinceEpoch <= b!;
  30. }
  31. static bool isBetweenTime(int a, int v, int? b) {
  32. DateTime vTime = DateTime.fromMillisecondsSinceEpoch(v);
  33. DateTime nowTime = DateTime(1, 1, 1, vTime.hour, vTime.minute, vTime.second);
  34. return a <= nowTime.millisecondsSinceEpoch &&
  35. nowTime.millisecondsSinceEpoch <= b!;
  36. }
  37. }