-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from IQuinteros/developing
Adding improvements and fixes
- Loading branch information
Showing
16 changed files
with
308 additions
and
143 deletions.
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
|
||
|
||
import 'package:intl/intl.dart'; | ||
|
||
class TextValidationUtil{ | ||
|
||
static bool validateEmail(String email) => RegExp(r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+").hasMatch(email); | ||
static bool validateRut(String rut) => RegExp(r"^(\d{1,3}(?:\.\d{1,3}){2}-[\dkK])$").hasMatch(rut) && _validRutDv(rut); | ||
|
||
static String stringToRut(String preRut){ | ||
if(preRut.isEmpty) return ''; | ||
if(preRut.length <= 1) return preRut; | ||
if(preRut.length > 1){ | ||
if(preRut.length > 9) preRut = preRut.substring(0, 9); | ||
if(preRut.indexOf('k') >= 0) preRut = preRut.substring(0, preRut.indexOf('k')+1); | ||
String withoutDv = preRut.substring(0, preRut.length - 1); | ||
final format = NumberFormat("##,###.###", "tr_TR"); | ||
String formattedWithoutDv = format.format(int.parse(withoutDv)); | ||
return formattedWithoutDv + preRut.replaceRange(preRut.length - 1, preRut.length, '-${preRut[preRut.length-1]}').substring(preRut.length - 1, preRut.length+1); | ||
} | ||
return preRut; | ||
} | ||
|
||
static int? getNumRutValue(String rut){ | ||
if(rut.isEmpty) return null; | ||
if(rut.split('-').length < 2) return null; | ||
final numberDotsString = rut.split('-')[0]; | ||
final numberString = numberDotsString.split('.').join(); | ||
print(numberString); | ||
return int.tryParse(numberString); | ||
} | ||
|
||
static String? getDvRutValue(String rut){ | ||
if(rut.isEmpty) return null; | ||
if(rut.split('-').length < 2) return null; | ||
return rut.split('-')[1]; | ||
} | ||
|
||
static bool _validRutDv(String rut){ | ||
if(rut.isEmpty) return false; | ||
if(rut.split('-').length < 2) return false; | ||
final numberDotsString = rut.split('-')[0]; | ||
final numberRevString = numberDotsString.split('.').join().split('').reversed.join(); | ||
List<int> results = []; | ||
for (var i = 0; i < numberRevString.length; i++) { | ||
int? number = int.tryParse(numberRevString[i]); | ||
if(number == null) continue; | ||
|
||
results.add(number * (i % 6 + 2)); | ||
} | ||
final sum = results.reduce((value, element) => value + element); | ||
final remainder = sum % 11; | ||
final dv = (11 - remainder) == 10? 'k' : (11 - remainder) == 11? '0' : (11 - remainder).toString(); | ||
return rut.split('-')[1].toLowerCase() == dv; | ||
} | ||
} |
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
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
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
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
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
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
Oops, something went wrong.