Skip to content

Instantly share code, notes, and snippets.

View ArefMozafari's full-sized avatar
🏠
Working from home

Aref Mozafari ArefMozafari

🏠
Working from home
View GitHub Profile
@ArefMozafari
ArefMozafari / DartGist6.dart
Last active July 27, 2021 12:54
Flutter/Dart - Range of Dates for today, current week, current month and current year in Shamsi/Persian/Jalali Calendar using shamsi_date package.
//First you need install shamsi_date package from pub.dev and then import it.
import 'package:shamsi_date/shamsi_date.dart';
void main (){
final JalaliRange todayRange =
JalaliRange(start: Jalali.now(), end: Jalali.now());
//Shamsi_date package doesn't support .add and .subtract (since this version)
//So we use DateTime and convert it to Jalali
final JalaliRange thisWeekRange = JalaliRange(
@ArefMozafari
ArefMozafari / DartGist5.dart
Last active July 27, 2021 09:58
Flutter/Dart - Regex that checks if password has at least specialCount special character matches
//Checks if password has at least specialCount special character matches
bool hasMinSpecialChar(String password, int specialCount) {
String pattern =
r"^(.*?[$&+,\:;/=?@#|'<>.^*()%!-]){" + specialCount.toString() + ",}";
return password.contains(new RegExp(pattern));
}
@ArefMozafari
ArefMozafari / DartGist4.dart
Created February 22, 2021 12:50
Flutter/Dart - Regex that Checks if password has at least numericCount numeric character matches
//Checks if password has at least numericCount numeric character matches
bool hasMinNumericChar(String password, int numericCount) {
String pattern = '^(.*?[0-9]){' + numericCount.toString() + ',}';
return password.contains(new RegExp(pattern));
}
@ArefMozafari
ArefMozafari / DartGist3.dart
Created February 22, 2021 12:49
Flutter/Dart - Regex that Checks if password has at least uppercaseCount uppercase letter matches
//Checks if password has at least uppercaseCount uppercase letter matches
bool hasMinUppercase(String password, int uppercaseCount) {
String pattern = '^(.*?[A-Z]){' + uppercaseCount.toString() + ',}';
return password.contains(new RegExp(pattern));
}
@ArefMozafari
ArefMozafari / DartGist2.dart
Last active August 5, 2021 17:11
Flutter/Dart - How to convert En/Fa entered number to each other
extension StringExtentions on String {
String replaceFaNumToEnNum() {
const english = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
const farsi = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
String value = this;
for (int i = 0; i < farsi.length; i++) {
value = value.replaceAll(farsi[i], english[i]);
}
@ArefMozafari
ArefMozafari / DartGist1.dart
Last active February 22, 2021 12:43
Flutter/Dart - How to add commas to a string number after each three digit
import 'package:flutter/services.dart';
import 'package:intl/intl.dart';
class NumericTextFormatter extends TextInputFormatter {
@override
TextEditingValue formatEditUpdate(
TextEditingValue oldValue, TextEditingValue newValue) {
if (newValue.text.isEmpty) {