Created
August 30, 2019 03:39
-
-
Save nirinium/ef3cfb66f861f571d80a06a60c947ec7 to your computer and use it in GitHub Desktop.
validators
This file contains hidden or 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
private bool StringValidator(string input) | |
{ | |
string pattern = "[^a-zA-Z]"; | |
if (Regex.IsMatch(input, pattern)) | |
{ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
//validate integer | |
private bool IntegerValidator(string input) | |
{ | |
string pattern = "[^0-9]"; | |
if (Regex.IsMatch(input, pattern)) | |
{ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
private void ClearTexts(string user, string pass) | |
{ | |
user = String.Empty; | |
pass = String.Empty; | |
} | |
internal bool IsLoggedIn(string user, string pass) | |
{ | |
if (string.IsNullOrEmpty(user)) | |
{ | |
MessageBox.Show("Enter the user name!"); | |
return false; | |
} | |
else if (StringValidator(user) == true) | |
{ | |
MessageBox.Show("Enter only text here"); | |
ClearTexts(user, pass); | |
return false; | |
} | |
else | |
{ | |
if (Username != user) | |
{ | |
MessageBox.Show("User name is incorrect!"); | |
ClearTexts(user, pass); | |
return false; | |
} | |
else | |
{ | |
if (string.IsNullOrEmpty(pass)) | |
{ | |
MessageBox.Show("Enter the passowrd!"); | |
return false; | |
} | |
//check password is valid | |
else if (IntegerValidator(pass) == true) | |
{ | |
MessageBox.Show("Enter only integer here"); | |
return false; | |
} | |
//check password is correct | |
else if (Userpassword != pass) | |
{ | |
MessageBox.Show("Password is incorrect"); | |
return false; | |
} | |
else | |
{ | |
return true; | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment