42 lines
1.4 KiB
Dart
42 lines
1.4 KiB
Dart
import 'package:cims_apps/application/theme/color_palette.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:intl/intl.dart';
|
|
|
|
class StringUtils {
|
|
static bool emailValidation(String email) {
|
|
return RegExp(
|
|
r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$')
|
|
.hasMatch(email);
|
|
}
|
|
|
|
static bool phoneValidation(String phone) {
|
|
return RegExp(r'^(\+62|62|0)8[1-9][0-9]{6,10}$').hasMatch(phone);
|
|
}
|
|
|
|
static bool passwordValidation(String password) {
|
|
return RegExp(r'^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*?[\W_])(?=.{8,})')
|
|
.hasMatch(password);
|
|
}
|
|
|
|
static String formatTime(DateTime? dateTime) {
|
|
if (dateTime != null) {
|
|
DateFormat formatter = DateFormat('HH:mm:ss');
|
|
return formatter.format(dateTime);
|
|
}
|
|
return '--:--:--';
|
|
}
|
|
|
|
static void iCopyToClipboard(BuildContext context,
|
|
{String? desc, required String text}) {
|
|
Clipboard.setData(ClipboardData(text: text));
|
|
ScaffoldMessenger.of(context)
|
|
.showSnackBar(SnackBar(
|
|
backgroundColor: ColorPalette.primary,
|
|
content: Text(desc ?? "Text copied to clipboard"),
|
|
))
|
|
.closed
|
|
.then((value) => ScaffoldMessenger.of(context).removeCurrentSnackBar());
|
|
}
|
|
}
|