Im some weeks now im trying to make my own validators for my mobile app ,the thing is that sometimes i get a feedback from my users that they cut them off and they are getting errors , im trying to find a solution everywhere but at least in frontend for flutter i cant find any reliable package … many of them are outdated at least 2-3 years.
Also i dont know what to allow and what not in password-email fields , do i need to cut off symbols or characters that can messed up my database or mysql2 can handle it ?
Does anyone have any solution for this or you guys use validators in backend only?
Thanks .
Here is my code :
bool isValidUsername(String username) {
final RegExp usernamePattern =
RegExp(r'^[p{L}p{N}_.-]{3,20}$', unicode: true);
return usernamePattern.hasMatch(username);
}
bool isValidEmail(String email) {
final RegExp emailPattern = RegExp(
r'^[^s@]+@[^s@]+.[^s@]+$',
unicode: true,
);
return emailPattern.hasMatch(email);
}
bool isValidPassword(String password) {
final RegExp passwordPattern = RegExp(
r'^[p{L}p{N}p{P}p{S}p{Zs}]{8,50}$',
unicode: true,
);
final RegExp problematicPattern = RegExp(
r'[x00-x1Fx7F]',
unicode: true,
);
return passwordPattern.hasMatch(password) &&
!problematicPattern.hasMatch(password);
}
2
Answers
Your email validation regex should be replaced with package:email_valid. A regex to match a valid email is around 2400 characters.
Also, if you practice proper placeholders for your SQL interactions, it should not matter at all what goes into your passwords. Stop filtering those. Especially review Correct Horse Battery Staple and permit anything the user wants, as long as there are enough bits.
I am utilizing the following class for validation purposes. This class is designed to be highly versatile and can be integrated into any application you develop. You have the flexibility to extend it by adding additional validation logic as required. Also you can customize it to meet your specific needs.