Merge pull request #16 from yaso-meth/username-vaslidation-fix
username validation fix
This commit is contained in:
@@ -48,11 +48,15 @@ class _MIHTextFieldState extends State<MIHTextField> {
|
|||||||
if (widget.hintText == "Email" && !isEmailValid(text)) {
|
if (widget.hintText == "Email" && !isEmailValid(text)) {
|
||||||
errorMessage += "Enter a valid email address\n";
|
errorMessage += "Enter a valid email address\n";
|
||||||
}
|
}
|
||||||
if (widget.hintText == "Username" && text.length < 8) {
|
// if (widget.hintText == "Username" && text.length < 8) {
|
||||||
errorMessage += "• Username must contain at least 8 characters.\n";
|
// errorMessage += "• Username must contain at least 8 characters.\n";
|
||||||
}
|
// }
|
||||||
if (widget.hintText == "Username" && !isUsernameValid(text)) {
|
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) {
|
if (errorMessage.isEmpty) {
|
||||||
return null;
|
return null;
|
||||||
@@ -62,8 +66,7 @@ class _MIHTextFieldState extends State<MIHTextField> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool isUsernameValid(String username) {
|
bool isUsernameValid(String username) {
|
||||||
return RegExp(r'^(?=[a-zA-Z0-9._]{8,20}$)(?!.*[_.]{2})[^_.].*[^_.]$')
|
return RegExp(r'^[a-zA-Z][a-zA-Z0-9_]{5,19}$').hasMatch(username);
|
||||||
.hasMatch(username);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isEmailValid(String email) {
|
bool isEmailValid(String email) {
|
||||||
|
|||||||
@@ -287,7 +287,7 @@ class _MIHErrorMessageState extends State<MIHErrorMessage> {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 15),
|
const SizedBox(height: 15),
|
||||||
Text(
|
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(
|
style: TextStyle(
|
||||||
color:
|
color:
|
||||||
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||||
|
|||||||
@@ -85,6 +85,8 @@ class _MIHHomeState extends State<MIHHome> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
void setAppsNewPersonal(List<MIHTile> tileList) {
|
void setAppsNewPersonal(List<MIHTile> tileList) {
|
||||||
|
ImageProvider logo = MzanziInnovationHub.of(context)!.theme.logoImage();
|
||||||
|
|
||||||
if (widget.signedInUser.fname == "") {
|
if (widget.signedInUser.fname == "") {
|
||||||
tileList.add(MIHTile(
|
tileList.add(MIHTile(
|
||||||
videoID: "jFV3NN65DtQ",
|
videoID: "jFV3NN65DtQ",
|
||||||
@@ -94,10 +96,9 @@ class _MIHHomeState extends State<MIHHome> {
|
|||||||
widget.signedInUser, widget.propicFile));
|
widget.signedInUser, widget.propicFile));
|
||||||
},
|
},
|
||||||
tileName: "Setup Profie",
|
tileName: "Setup Profie",
|
||||||
tileIcon: Icon(
|
tileIcon: Padding(
|
||||||
Icons.perm_identity,
|
padding: const EdgeInsets.all(15.0),
|
||||||
color: getSec(),
|
child: Image(image: logo),
|
||||||
size: 230,
|
|
||||||
),
|
),
|
||||||
p: getPrim(),
|
p: getPrim(),
|
||||||
s: getSec(),
|
s: getSec(),
|
||||||
|
|||||||
@@ -214,8 +214,7 @@ class _ProfileUserUpdateState extends State<ProfileUserUpdate> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool isUsernameValid(String username) {
|
bool isUsernameValid(String username) {
|
||||||
return RegExp(r'^(?=[a-zA-Z0-9._]{8,20}$)(?!.*[_.]{2})[^_.].*[^_.]$')
|
return RegExp(r'^[a-zA-Z][a-zA-Z0-9_]{5,19}$').hasMatch(username);
|
||||||
.hasMatch(username);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> submitForm() async {
|
Future<void> submitForm() async {
|
||||||
|
|||||||
Reference in New Issue
Block a user