Merge pull request #16 from yaso-meth/username-vaslidation-fix

username validation fix
This commit is contained in:
yaso-meth
2024-11-30 01:51:36 +02:00
committed by GitHub
4 changed files with 16 additions and 13 deletions

View File

@@ -48,11 +48,15 @@ class _MIHTextFieldState extends State<MIHTextField> {
if (widget.hintText == "Email" && !isEmailValid(text)) {
errorMessage += "Enter a valid email address\n";
}
if (widget.hintText == "Username" && text.length < 8) {
errorMessage += "• Username must contain at least 8 characters.\n";
}
// if (widget.hintText == "Username" && text.length < 8) {
// errorMessage += "• Username must contain at least 8 characters.\n";
// }
if (widget.hintText == "Username" && !isUsernameValid(text)) {
errorMessage += "• Username can only contain '_' special Chracters.\n";
errorMessage += "Let's create a great username for you!\n";
errorMessage += "• Your username should start with a letter.\n";
errorMessage += "• You can use letters, numbers, and/ or underscores.\n";
errorMessage += "• Keep it between 6 and 30 characters.\n";
errorMessage += "• Avoid special characters like @, #, or \$.\"\n";
}
if (errorMessage.isEmpty) {
return null;
@@ -62,8 +66,7 @@ class _MIHTextFieldState extends State<MIHTextField> {
}
bool isUsernameValid(String username) {
return RegExp(r'^(?=[a-zA-Z0-9._]{8,20}$)(?!.*[_.]{2})[^_.].*[^_.]$')
.hasMatch(username);
return RegExp(r'^[a-zA-Z][a-zA-Z0-9_]{5,19}$').hasMatch(username);
}
bool isEmailValid(String email) {

View File

@@ -287,7 +287,7 @@ class _MIHErrorMessageState extends State<MIHErrorMessage> {
),
const SizedBox(height: 15),
Text(
"Your username needs a little adjustment. To make sure everyone has a unique username, please start your username with a letter or number and use only letters, numbers or underscores. Let's try that again!",
"Let's create a great username for you! Just a few quick tips:\n• Your username should start with a letter.\n• You can use letters, numbers, and/ or underscores.\n• Keep it between 6 and 20 characters.\n• Avoid special characters like @, #, or \$.\"",
style: TextStyle(
color:
MzanziInnovationHub.of(context)!.theme.secondaryColor(),

View File

@@ -85,6 +85,8 @@ class _MIHHomeState extends State<MIHHome> {
);
void setAppsNewPersonal(List<MIHTile> tileList) {
ImageProvider logo = MzanziInnovationHub.of(context)!.theme.logoImage();
if (widget.signedInUser.fname == "") {
tileList.add(MIHTile(
videoID: "jFV3NN65DtQ",
@@ -94,10 +96,9 @@ class _MIHHomeState extends State<MIHHome> {
widget.signedInUser, widget.propicFile));
},
tileName: "Setup Profie",
tileIcon: Icon(
Icons.perm_identity,
color: getSec(),
size: 230,
tileIcon: Padding(
padding: const EdgeInsets.all(15.0),
child: Image(image: logo),
),
p: getPrim(),
s: getSec(),

View File

@@ -214,8 +214,7 @@ class _ProfileUserUpdateState extends State<ProfileUserUpdate> {
}
bool isUsernameValid(String username) {
return RegExp(r'^(?=[a-zA-Z0-9._]{8,20}$)(?!.*[_.]{2})[^_.].*[^_.]$')
.hasMatch(username);
return RegExp(r'^[a-zA-Z][a-zA-Z0-9_]{5,19}$').hasMatch(username);
}
Future<void> submitForm() async {